What are Functional Components in ReactJS?
Understanding Functional Components in ReactJs?
You will often come across functional components while working in React. A functional component in React is like a JavaScript/ES6 function that returns a React element (JSX).
You can create a functional component in React by writing a JavaScript function and they may or may not receive data as parameters.
Example:
function Welcome(props) {
return
Hello, {props.name}
;
}
Introduction of React Hooks for Functional Components
As discussed earlier, the functional components are created using the JavaScript functions. These components accept props and show the output as a React element.
In the first quarter of 2019, Hooks were introduced to the ReactJS with the React v16 8.0. With this, the functional components found some additional capabilities which allowed these to work similar to class components.
Hence, the arrival of Hooks in ReactJS has made it easier to write React functional components in modern apps. To be precise, Hooks allows developers to make use of the states without having to write class components.
Test your knowledge with a quick quiz!
What is the use of Hooks in functional components?
Select the correct answer