While going through the docs find that render function is a essential life cycle method. In the case of functional components ,there is no render function.?
CodePudding user response:
Yes when using class components componentDidMount, componentWillUnmount(), render() are essential life cycle methods. In react functional components there is the useEffect Hook and in your case the:
return (
<div>
<h1>Header</h1>
<div/>
);
to replace the render function
CodePudding user response:
Yes, you are correct. In functional components, there is no need for a render function.
A functional component is just a plain JavaScript function that returns JSX. A class component is a JavaScript class that extends React.Component which has a render method. When defining a class component, you have to make a class that extends React.Component. The JSX to render will be returned inside the render method.
Source: https://www.twilio.com/blog/react-choose-functional-components
