【发布时间】:2018-01-30 13:28:23
【问题描述】:
我正在尝试将 [stateless component of] React/Redux 应用程序中的选择填充为:
const FillSelect = ({team}) => <option value={team.onboardingOrder}>{team.name}</option>
const TeamSelector = ({teams}) => {
return (
<select>
<option value="">All</option>
{
teams ? (teams => teams.map(team => <FillSelect team={team} />)) : null
}
</select>
)
}
团队看起来像:{0:{id: 1, name: "Program Management", onboardingOrder: 0, …}, 1: {id: 2, name: "Value Capture", onboardingOrder: 1, …}…}。
返回错误:Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
in select ...
这是因为我使用的是map()吗?这样做的正确方法是什么?
【问题讨论】:
-
另外,你不能
map一个对象。使用Object.values(teams).map... -
不能
map任何对象,但支持迭代,对吧? developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
标签: javascript reactjs redux immutable.js