【发布时间】:2020-12-01 18:35:14
【问题描述】:
我有一个 templates.js 文件,我在其中手动设置值:
export const galleries = [{name:'default'},{name:'carousel'},{name:'grid',set:true}];
如果对象包含{set:true} 我想在product.js 页面上呈现特定组件。
我在想:
const gallery = galleries.find(gallery=>gallery.set==true).name
然后渲染:
<div>
gallery == "grid" ? (
<Grid />
) : gallery == "carousel" ? (
<Carousel />
) : (
<Default />
)
</div>
不过有点乱……
有没有更好的方法或者已经有一个包可以做到这一点?
【问题讨论】:
标签: reactjs next.js react-component