新しいアイテムをState array
ofにプッシュしようとしていますがobjects
、問題が発生しています。以下は私のコードです。私は何か間違っていると確信しています
constructor(props) {
super(props);
this.state = {
bill: []
};
}
componentWillReceiveProps(nextProps, nextState) {
if (nextProps.bills !== this.props.bills) {
let billsObj = nextProps.bills
billsObj.map((billsObj) => {
var joined = this.state.bill.concat({billId:billsObj.id,checked:false});
console.log(joined, "joined", this.state.bill)
this.setState({
bill: [...this.state.bill, ...joined]
}, () => {
console.log(this.state.bill, billsObj.id)
})
})
}
}
でcomponentWillReceiverProps
を取得しarray
、それをマッピングして に値をプッシュしますがstate
array
、最終的には 配列 で単一の値しか取得していませんが、props array
11 個の値があり、 my で単一の値しか取得していませんstate array
。助けを得たいと思っています。