Skip to content

Instantly share code, notes, and snippets.

@fdaciuk
Created October 10, 2018 14:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdaciuk/04a8dbc143def85a220754ee70b6e145 to your computer and use it in GitHub Desktop.
Save fdaciuk/04a8dbc143def85a220754ee70b6e145 to your computer and use it in GitHub Desktop.
React: setState onBlur
import React from 'react'
class App extends React.Component {
state = { cep: '' }
handleBlur = (e) => {
this.setState({ cep: e.target.value })
}
render () {
return (
<React.Fragment>
<input type='text' onBlur={this.handleBlur} />
{this.state.cep && <span>CEP: {this.state.cep}</span>}
</React.Fragment>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment