我试图设置状态以响应Api onClick。状态获得更新,但是当我第一次单击时没有更新,第二次单击是的,它的确更新了。
fetch(URL)
.then(res => res.json())
.then(res => {
this.setState({
recipesList: res
});
});
console.log(this.state.recipesList);
};
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗 ?
所以我有里面有对象的数组。该对象有一个属性调用名称,它是一串值
如何返回名称属性中包含“apples”的对象
fruits = [
{
name: 'apples, lemon',
quantity: 2
},
{
name: 'bananas, pearl',
quantity: 0
},
{
name: 'cherries,
pineapple',
quantity: 5
}
];
Run Code Online (Sandbox Code Playgroud)