React有条件地设置组件属性



是否有任何方法可以在header中存储section.type不同的标题,如<p> {section.title1} </p><p> {section.title2} </p>?

return (
<Collapse
onToggle={onHandleClick}
header={
<p> {section.title1} </p>
}
</Collapse>
);

是的,你可以这样做:

header={
<p> {section.type ? section.title1 : section.title2} </p>
}

你可以做一个条件渲染:

return (
<Collapse
onToggle={onHandleClick}
header={
section.type ? <p>{section.title1}</p> : <p>{section.title2}</p>
}
</Collapse>
)

最新更新