Created
December 5, 2021 23:56
-
-
Save natafaye/8d87f2dc2b2fb207beaaa787e0dec025 to your computer and use it in GitHub Desktop.
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
addLike() { | |
//this.state.transactionList = fdjskflds // DO NOT CHANGE STATE DIRECTLY | |
// let something = this.state.transactionList.push({ fdjskfldsfjklds }) // DO NOT CHANGE STATE DIRECTLY | |
// this.setState({ transactionList: something }) | |
this.setState(state => ({ numLikes: state.numLikes + 1 }) ) | |
// adding | |
this.setState( state => ({ transactionList: [ ...state.transactionList, "fdsfdsfsd"] }) ) | |
this.setState( state => ({ transactionList: state.transactionList.concat(["fdsfdsfsd"]) }) ) | |
// deleting | |
this.setState( state => ({ transactionList: state.transactionList.filter(t => t.id !== idToDelete ) }) ) | |
// update one transaction | |
this.setState( state => ({ transactionList: state.transactionList.map(t => { | |
if(t.id === idToUpdate) { | |
return { ...t, amount: 20 } | |
} | |
else { | |
return t; | |
} | |
}) | |
}) | |
) | |
// simplified version of previous | |
this.setState( state => ({ transactionList: state.transactionList.map( t => (t.id === idToUpdate) ? { ...t, amount: 20 } : t ) }) ) | |
// stretched out version of previous | |
this.setState( state => { | |
const newTransactionList = [...state.transactionList] | |
newTransactionList[3] = { ...newTransactionList[3], amount: 20 } | |
return { transactionList: newTransactionList } | |
}) | |
//this.state.transactionList[3] = { ...transactionToUpdate, amount: 20 } // DO NOT CHANGE STATE DIRECTLY | |
} | |
// TODO | |
// { people: [ Simone, Maria, Chance ]} | |
// { people: [ Simone ]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment