You're refactoring a class component that contains several lifecycle methods into a functional component. What feature of React would you use to handle side effects in the functional component?

  • useState and useEffect
  • render method
  • componentDidMount and componentDidUpdate
  • constructor and componentWillUnmount
In a functional component, you can handle side effects using useState to manage state and useEffect to perform side effects. These hooks replace the lifecycle methods found in class components, making it more concise and easier to manage side effects. componentDidMount and componentDidUpdate are lifecycle methods used in class components, not in functional components. The other options are also not the correct way to handle side effects in functional components.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *