react 再レンダリング
stateのデータを更新する時に、 更新の方法によっては再レンダリングがされなくて一覧のデータが更新されない
stateの更新の方法
stateを配列で持っていたとする
this.state = { tweets: [] }
更新する
## NGパターン handleSave(){ const newTweets = this.state.tweets newTweets.push({body:"tweet"}) this.setState({tweets: newTweets}) } ## OKパターン handleSave(){ const newTweets = Object.assign([],this.state.tweets) newTweets['id'] = {body:"tweet"} this.setState({tweets: newTweets}) }
オブジェクトIDの話?になるのか別のオブジェクトに一度作り直さないと再度レンダリングされない