Which of the following is a method to update state in class components in React?

  • this.setState({})
  • useState()
  • updateState()
  • this.state = {}
In class components in React, you can update state using the this.setState({}) method. This method allows you to modify the component's state and triggers a re-render. The other options are not valid ways to update state in class components. useState() is used in functional components, updateState() is not a built-in method, and directly modifying this.state is discouraged.
Add your answer
Loading...

Leave a comment

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