Created
December 17, 2017 04:00
-
-
Save Nicknyr/f644e25dd5f84aaa3d6a2bfe1bf01d1e to your computer and use it in GitHub Desktop.
Updating state in React with a form input box example
This file contains 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
import React, { Component } from 'react'; | |
import './App.css'; | |
export default class ToDoList extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
userInput: '', | |
list: [] | |
} | |
} | |
changeUserInput(input) { | |
this.setState({ | |
userInput: input | |
}); | |
} | |
render() { | |
return ( | |
<div className="to-do-list-main"> | |
<input | |
onChange={ (e) => this.changeUserInput(e.target.value)} | |
value={this.state.userInput} | |
type="text" | |
/> | |
<button>Press Me</button> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment