• +91 9723535972
  • info@interviewmaterial.com

ReactJS Interview Questions and Answers

Related Subjects

Question - What do you understand by the state in React?

Answer -

In react, the state of a component is an object that holds some information that may change over the component's lifetime. It would be best to try to make your state as simple as possible and minimize the number of stateful components.

Let's see how to create a user component with message state:

class User extends React.Component {  
  constructor(props) {  
    super(props)  
    this.state = {  
      message: 'Welcome to React world'  
    }  
  }  
  render() {  
    return (  
     
  
       

{this.state.message}

  
     
  
    )  
  }  
}   
The state is very similar to props, but it is private and fully controlled by the component. i.e., It is not accessible to any other component till the owner component decides to pass it.

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners