Skip to content

Instantly share code, notes, and snippets.

@artobay
Created June 12, 2018 04:00
Show Gist options
  • Select an option

  • Save artobay/360ada672bd938cd7b7a44ce0eea72dd to your computer and use it in GitHub Desktop.

Select an option

Save artobay/360ada672bd938cd7b7a44ce0eea72dd to your computer and use it in GitHub Desktop.
State in React

https://www.youtube.com/watch?v=qh3dYM6Keuw

State:

  • by default is null so you can set it to what you want
  • only place you set your initial state is in constructor
  • whenever state changes it will rerender and update the DOM it will only updated affected node no lets see how we change it
  • go in the render method then you can change the set for ex:
  • React take care of DOM manipulation for us.
  • Use State --> only get used when component has internal value and that only affect that component.
render() {

setTimeout(() => {
        this.setState({name:"BoB"});       
}, 1000)  
constructor () {
   super() 
   this.state = {name: "Will } 
}

then you can access this by entering this states name so -->

render() { return (

{this.state.name}

);

}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment