Created
July 6, 2018 21:52
-
-
Save amankkg/5b22295a9eba87771346bd43601c7032 to your computer and use it in GitHub Desktop.
simple form and controlled input
This file contains 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
class Form extends React.Component { | |
state = { value: '' } | |
onChange = e => this.setState({ value: e.currentTarget.value }) | |
onSubmit = () => console.log('The value is ', this.state.value) | |
render() { | |
return ( | |
<form onSubmit={this.onSubmit}> | |
<label> | |
Value: <input value={this.state.value} onChange={this.onChange} /> | |
</label> | |
<br /> | |
{this.state.value.length > 10 && <p>hey, try to keep in short</p>} | |
<button type="submit">Submit</button> | |
</form> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment