React Component

React components are independent and can be reused.

React provides two types of components 
    1. Class Components
    2. Functional Components

1. Class Components:
        class App extends React.Component{
                render(){
                    return <></>;
                }
        }

To display elements of a component, render the component as:
        ReactDOM.render(<App />, document.getElementById("root"));

2. Functional Component
         you can create a functional component using a normal Javascript function.

       function App(){
             return (
                   <>
                       <h1>Hello World</h1>
                   </>
              );
       }

To display elements of a component, render the component as:
        ReactDOM.render(<App />, document.getElementById("root"));

In previous versions of ReactJS i.e. before React 16.8 version, class Components were the only way to create component in React. Functional Components were considered as state-less.
     But in newer versions of React, hooks were introduced to work with lifecycle and state of the application. Thus, providing the same functionality as class Components.

Continue Reading: Create a component to render user details on a web page using userDetails



Comments

Popular Posts