Last active
June 7, 2018 14:01
-
-
Save LukeMwila/4d8127796ee292eaf511586a6b18116f to your computer and use it in GitHub Desktop.
Understanding State in React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
class MyComponent extends Component{ | |
state = { | |
superHero: '' | |
} | |
/** Update the state */ | |
updateFavouriteSuperHero(e){ | |
e.preventDefault() | |
this.setState({ superHero: e.target.value }) | |
} | |
render(){ | |
return( | |
<div> | |
My favourite super hero is {this.state.superHero}<br /> | |
<input onChange={(e) => this.updateFavouriteSuperHero(e)} placeholder='Type favourite superhero' /> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment