Skip to content

Instantly share code, notes, and snippets.

@iamparthaonline
Last active January 28, 2022 07:50
Show Gist options
  • Select an option

  • Save iamparthaonline/bfffd6ac88cc701257c407660bd87c80 to your computer and use it in GitHub Desktop.

Select an option

Save iamparthaonline/bfffd6ac88cc701257c407660bd87c80 to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
class ControlledComponent extends Component {
constructor(props) {
super(props);
this.state = {
text: ""
};
}
render() {
return (
<div>
<form>
<div>
<label>Controlled Input </label>
<input
type="number"
name="sentence"
onChange={(event) => {
this.setState({
text: event.target.value,
});
}}
value={this.state.text}
/>
</div>
<button type="submit">Submit</button>
</form>
</div>
);
}
}
export default ControlledComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment