Functional Component and useState() in ReactJS

Viewed 73

So based upon my understanding, in ReactJS, when the state of a component changes the render method is re-executed again.

But what if I use a functional component and use useState() to initialize and change the state of the functional component?

Since a functional component does not have any render method what part of it is rendered again?

1 Answers

Short Answer:

The while function is re-executed, you can test that using debugger or logging.

Long Answer:

The functional component acts like a render method itself. if you are converting it from class to functional. As you get scope to write JS for handlers, in the function and get the return statement scope for the JSX.

So answering your question here, the complete function(acting as a functional component) executed. You can read further at: https://reactjs.org/docs/hooks-state.html

Related