componentWillMount
doesn't trigger rendering, as stated in the documentation.
However, you can change state in componentDidMount
, which will result in rendering your component twice.
Moreover, you should probably replace
{this.state.values.map((value:any)=>{
<li>{value.name}</li>
})}
with
{
this.state.values.map((value: any, index: number) => {
return <li key={index}>{value.name}</li>)
}
}
as your current piece of code doesn't return a JSX object. Finally, try to use a real key
instead of index
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…