Last active
March 11, 2019 10:12
-
-
Save gladchinda/09deaa88417a3448d0c5074ecf1988ef to your computer and use it in GitHub Desktop.
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
class UncontrolledFormInput extends React.Component { | |
constructor(props) { | |
super(props); | |
this.inputField = React.createRef(); | |
this.handleChange = this.handleChange.bind(this); | |
this.state = { value: "Glad" }; | |
} | |
handleChange(evt) { | |
this.setState({ value: this.inputField.current.value }); | |
} | |
render() { | |
return ( | |
<div> | |
<h1>Hello {this.state.value}!</h1> | |
{/* Attach the created ref: this.inputField */} | |
<input type="text" ref={this.inputField} defaultValue={this.state.value} onChange={this.handleChange} placeholder="Enter your name" /> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment