Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save domitriusclark/e317452ca6ac3f5a4a8f887f06f29f3b to your computer and use it in GitHub Desktop.
Save domitriusclark/e317452ca6ac3f5a4a8f887f06f29f3b to your computer and use it in GitHub Desktop.
Input state manipulation
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