How to create components in ReactJS?

Technology CommunityCategory: ReactHow to create components in ReactJS?
VietMX Staff asked 3 years ago

There are two possible ways to create ReactJS Components.

  1. Functional components: This is the simplest way to create ReactJS components. It accepts props as an Object and returns ReactJS elements. We call it as “functional” because those are pure JavaScript functions.
	function Greeting(props) {
   	   return <h1> Hello, {props.message}</h1>}
  1. Class components: You can also use Es6 class to define component. The above functional component can be written as below,
      class Greeting extends React.Component {
  	    render() {
    		    return <h1>Hello, {this.props.message}</h1>;
  	        }
	    }