I have the array of objects which contain components and title now I would like to display these components based on id passed in URL parameters I can do that if its just array using find function, unfortunately, I can't figure how to do the same with an array of objects,
Here is part of my code
//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;
});`
And I display the components like this
<div>
<SelectedComponents />
</div>
But I get an error as follows
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.
What do I need to change to get this working as expected?