daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Oct 13th, 2017 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function AddPerson(props) {
  2.     return(
  3.         <div>
  4.             <input name='newFirstName' type="text" value= {props.newFirstName} onChange = {props.handleUpdate}/>
  5.             <input name='newLastName' type="text" value= {props.newLastName} onChange = {props.handleUpdate}/>
  6.             <button type="submit" onClick= {props.addNewFriend}> Add New </button>
  7.         </div>
  8.     )
  9. }
  10.  
  11. class App extends Component {
  12.     constructor(props) {
  13.         super(props)
  14.         this.state = {
  15.             newPerson: '',
  16.             people: [
  17.                 {
  18.                     firstName:'Eric',
  19.                     lastName:'Andrews',
  20.                 },
  21.                 {
  22.                     firstName:'Rick',
  23.                     lastName:'Johnson',
  24.  
  25.                 },
  26.                 {
  27.                     firstName:'Yoni',
  28.                     lastName:'Arken',
  29.                 }
  30.             ],
  31.         };
  32.  
  33.         this.handleUpdate = this.handleUpdate.bind(this)
  34.     }
  35.  
  36. handleUpdate(e) {
  37.     this.setState({[e.target.name] : e.target.value})
  38.     //this updates state, but I want it to modify newPerson inside of state
  39. }
RAW Paste Data
Top