Chrome Extension

Bind form or input elements with state in React

class CName extends Component {
    constructor() {
        this.state = {
            firstname: ''
        }
    }

    handleInputChange = (e) => {
        this.setState({
            firstname: e.target.value
        });
    }

    render() {
        return (
            <div>
                <input type="text" value={this.state.firstname} onChange={this.handleInputChange} />
            </div>
        );
    }
}
Was this helpful?
0 Comments
Never leave your website again in search of code snippets by installing our chrome extension.