![](/img/trans.png)
[英]map function loop when rendering with ReactJS and concat JSX syntax
[英]Rendering Multiple jsx with map and contains throws syntax error : ReactJS
我正在嘗試使用map
呈現 jsx,然后使用includes
基於列表中存在的值顯示文本。 它拋出錯誤說"message": "Unexpected token. Did you mean
{'}'} or
}`。有人可以幫我解決這個問題
我嘗試過的代碼:
return (
<>
{list.length
?
list.map((item, idx) => {
return (
<span key={idx}>
{item}
</span>
)}
{list.includes("Test") && (
<span key="test">
Replacement
</span> )
}
)
: "-"}
</>
);
關閉大括號后,您在map
function 中調用list.includes
。 我想你想要這樣的東西:
return (
<>
{list.length
?
(<>
{list.map((item, idx) => {
return (
<span key={idx}>
{item}
</span>
)}
)}
{list.includes("Test") && (
<span key="test">
Replacement
</span> )
}
</>)
: "-"}
</>
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.