I want to return a tag from a method so that once I call the method the tags are returned and these tags are used to call a component.
const Populate =() =>
{
let tags = [];
analysisinfo.forEach((_item,index) =>
{
if(analysisinfo[index].id!== defaultid)
tags.push(<AU props={analysisinfo[index]} instance ={index}/>);
console.log({tags});
}
return tags;
let me explain in-detail the analysisinfo is an useState array which contains the below values. These values are being passed into this method.
0:
cpu: true
hdd: true
id: "00000000000000000000000000000000"
ram: true
And pushes these values into tags[]. I want them pushed into array in the form of a <>, so that when I return it calls the <AU..../> tag component which takes the above values as props.
Use a combination of filter and map:
const Populate = () => (
<>
{
analysisinfo
.filter(i => i.id !== defaultid)
.map((i, idx) => (
<AU props={i} instance={idx} />
))
}
</>
);