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.
Loading...
Related Quiz
- What is the difference between Imperative and Declarative in React?
- How to enable production mode in React?
- A component has a button which, when clicked, changes the text of a paragraph from "Inactive" to "Active". How would you test this behavior using React Testing Library?
- In the context of React development, how does a Service Worker contribute to the performance and reliability of a web application?
- JSX gets compiled into ________ by tools like Babel.