【发布时间】:2021-06-10 00:44:25
【问题描述】:
我现在有一个包含组件和标题的对象数组对一组对象做同样的事情,
这是我的部分代码
//array of objects
const templates =[
{
title: "TemplateOne",
component: TemplateOne,
},
{
title: "TemplateTwo",
component: TemplateTwo,
}]
//find the component and match the id passed in URL parameters
let SelectedComponent = templates.find(function (Component, idx) {
if (idx === Number(templateId)) {
return true;
}
return false;
});`
我这样显示组件
<div>
<SelectedComponents />
</div>
但我收到如下错误
index.js:1 Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
我需要进行哪些更改才能使其按预期工作?
【问题讨论】:
标签: javascript arrays reactjs react-hooks