In which type of components can you directly use the setState method?
- Both class-based and functional components
- Class-based components
- Functional components with hooks
- Neither class-based nor functional components
You can directly use the setState method in class-based components. Functional components with hooks use the useState hook instead to manage state. So, setState is typically associated with class-based components, and using it in functional components will result in an error.
Loading...
Related Quiz
- What is the use of the ownProps parameter in mapStateToProps() and mapDispatchToProps()?
- In what scenario might you choose the Context API over Redux for state management?
- Why should not call setState in componentWillUnmount?
- What is the difference between super() and super(props) in React using ES6 classes?
- Your team is experiencing issues with components re-rendering unnecessarily. What immutable state handling technique could help mitigate unnecessary re-renders?