我想循环除第一个Alert
例如
const selection = (player, matchId, key) => (
<ul>
<li key={key}>1</li>
</ul>
);
return (
<div>
{(match.live) ? <Alert>This is an alert</Alert> && match.players.map((player, ix) => (
selection(player, match.matchId, ix)
)) : null}
</div>
当我将key
传递给列表元素但Alert
未显示
答案 0 :(得分:2)
重新整理您的选择是不可能的?
const selection = (player, matchId, key) => (
<li key={key}>1</li>
);
return (
<div>
<ul>
<li><Alert>This is an alert</Alert></li>
{match.players.map((player, ix) => (
selection(player, match.matchId, ix)
)) : null}
</ul>
</div>
)
只需执行
即可完全避免selection
return (
<div>
<ul>
<li><Alert>This is an alert</Alert></li>
{match.players.map((player, ix) => (
<li key={ix}>1</li>
)) : null}
</ul>
</div>
)
..但是,既然你正在传递玩家和matchId,我假设你有更大的selection
例程计划。