在下面的代碼中,我需要將<li>
html元素的文本設置爲粗體,當變量isActive爲true時否則文本應呈現爲純文本。有條件地呈現在反應中
目前我收到以下錯誤:
Objects are not valid as a React child (found: object with keys {title}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of
Navigation
如何解決呢?
import React from 'react'
const idSuffix = 'navigation__'
const Navigation = ({ onClick, id, title, tooltip, isActive }) => (
<li id={`${idSuffix}${id}`} onClick={onClick} alt={tooltip} data-active={isActive}>
{isActive ? <b>{title}</b> : {title} }
</li>
)
export default Navigation
我可以確認標題是一個字符串,並且如果使用下面的組件正確呈現
'{isActive? {title}:title}',最好使用className作爲 – elmeister