class App extends React.Component {
constructor(props) {
super(props);
this.state = { inpVal: "" };
this.inputRef = React.createRef();
}
handleSubmit = (e) => {
e.preventDefault();
this.setState({ inpVal: this.inputRef.current.value });
};
render() {
return (
<form>
<h1>{this.state.inpVal}</h1>
<TextInput ref={this.inputRef} />
<button type="submit">Submit</button>
</form>
);
}
}
export default App;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter