how to use react.js in javascript

To use React.js in JavaScript, you'll first need to install it using a package manager like npm or Yarn. Next, you'll need to import the React and ReactDOM libraries in your JavaScript file like so:

index.tsx
import React from 'react';
import ReactDOM from 'react-dom';
61 chars
3 lines

Once you have imported the libraries, you can start creating React components. A React component is a reusable piece of UI that you can render to the page. Here's an example of a simple React component in JavaScript:

index.tsx
import React from 'react';

class ExampleComponent extends React.Component {
  render() {
    return (
      <div>
        <h1>Hello, world!</h1>
      </div>
    );
  }
}

ReactDOM.render(<ExampleComponent />, document.getElementById('root'));
245 chars
14 lines

In this example, we've created a class called ExampleComponent that extends the React.Component class. This class has a single method called render that returns some JSX (a syntax extension for JavaScript that allows you to write HTML-like code in your JavaScript). We then use the ReactDOM.render method to render this component to the page.

gistlibby LogSnag