Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class App extends Component {
- state = {
- name: '',
- username: '',
- location: '',
- password: '',
- }
- setValue = (fieldName) => (evt) => this.setState({ [fieldName]: evt.target.value });
- render() {
- const { name, username, location, password } = this.state;
- return (
- <div className="App">
- <p>Name: {name}</p>
- <input onChange={this.setValue('name')} value={name} />
- <p>Username: {username}</p>
- <input onChange={this.setValue('username')} value={username} />
- <p>Location: {location}</p>
- <input onChange={this.setValue('location')} value={location} />
- <p>Password</p>
- <input onChange={this.setValue('password')} value={password} />
- </div>
- )
- }
- }
Add Comment
Please, Sign In to add comment