Practice
There are two possible ways to create a component.
Function components: this is the simplest way to create a component. These are pure JavaScript functions that take a props object as their first parameter and return React elements:
function Greeting({ message }) {
return <h1>{`Hello, ${message}`}</h1>
}
Class components: You can also use an ES6 class to define a component. The function component above can be written as:
class Greeting extends React.Component {
render() {
return <h1>{`Hello, ${this.props.message}`}</h1>
}
}
Comments