Every React component must have a render()
function . The render function is used to return the HTML to be displayed in the component. If multiple HTML elements need to be rendered, they need to be grouped together in a single enclosing tag (parent tag), eg <div>
, <form>
, , <group>
etc. This function returns the same result every time it is called.
Example: If you need to display the title, you can do it as follows:
import React from 'react'
class App extends React.Component {
render (){
return (
<h1>Hello World</h1>
)
}
}
export default App
js
Precautions:
- Each
render()
function contains a return statement. return
A statement can only have one parent HTML tag.