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.
Add your answer
Loading...

Leave a comment

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