//Function
const getThingName = (allCategories, id) => {
const categoryName = _.find(allCategories, {items: [{id}]}).name;
return categoryName;
}
//Component
const ThingsListView = ({ allCategories, .... }) => {
console.log(JSON.stringify(allCategories))
return (
<ScrollView>
<View>
...
{(thingsByUser &&
thingsByUser.length && (
<List>
{thingsByUser.map(({ id }, idx) => (
...
<CardText>{getThingName(allCategories, id)}</CardText>
console.log(JSON.stringify(allCategories))
返回正确的结果,如果我不进行以下函数调用:getThingName(allCategories, id)
但是当我打电话时,console.log(JSON.stringify(allCategories))
返回的是不确定的。
奇怪但真实!!我的目标是访问getThingName()中的allCategories数组值。