Created
October 4, 2018 17:49
-
-
Save domitriusclark/e317452ca6ac3f5a4a8f887f06f29f3b to your computer and use it in GitHub Desktop.
Input state manipulation
This file contains hidden or 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'; | |
const ShowingYourName = (props) => { | |
return ( | |
<p>{props.firstName}</p> | |
) | |
} | |
class App extends Component { | |
state = { | |
firstName: '' | |
}; | |
saveToState = (e) => { | |
this.setState({ | |
[e.target.name]: e.target.value | |
}); | |
} | |
render() { | |
return ( | |
<div className="center-this"> | |
<input type="text" name="firstName" placeholder="What is your first name..." value={this.state.firstName} onChange={this.saveToState} /> | |
<ShowingYourName firstName={this.state.firstName} /> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment