Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Last active March 11, 2019 10:12
Show Gist options
  • Save gladchinda/09deaa88417a3448d0c5074ecf1988ef to your computer and use it in GitHub Desktop.
Save gladchinda/09deaa88417a3448d0c5074ecf1988ef to your computer and use it in GitHub Desktop.
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