Explain the purpose of render() in React

bookmark

It is mandatory for each React component to have a render() function. Render function is used to return the HTML which you want to display in a component. If you need to rendered more than one HTML element, you need to grouped together inside single enclosing tag (parent tag) such as <div>, <form>, <group> etc. This function returns the same result each time it is invoked.

Example: If you need to display a heading, you can do this as below.

import React from 'react'  
   
class App extends React.Component {  
   render (){  
      return (  
         <h1>Hello World</h1>  
      )  
   }  
}  
export default App