在下面的代码中,我需要将<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