なぜこのコードは機能しませんか? 私はちょうどこのクラスの状態を小道具から設定したいが、状態は常に空である。州の値を小道具から設定できません
class BillsList extends React.Component{
constructor (props: any){
super(props);
this.state = {currentList : this.props.list};
};
render(){
console.log(this.props.list); //It worked..!
console.log(this.state.currentList); //But this is empty
return(
<div className="bill_list">
{this.state.currentList.map((item,i)=>
<BillsItem key ={i} value={item} />
)}
</div>
)
}
};
'リスト' この enter image description here
感謝をしたいと思いますが、それはそれは私のために働い –
どちらか動作しません。とにかくあなたはこれ以上の情報を読むことができます:https://medium.com/@justintulk/react-anti-patterns-props-in-initial-state-28687846cc2e –