I have a component which accepts an array as a prop
<Component runners={['1','2']}/>
Within this functional component, I want to render an element for each value in he array. My logic is:
const { runners } = props
if(runners.includes('1')) {
return(<ElementOne/>)
}
if(runners.includes('2')) {
return(<ElementTwo/>)
}
etc...
the includes
method throws an error runners.includes is not a function
. Same for indexOf
. So I check typeOf runners
which returns object
. Then I output JSON.stringify(runners)
. And it returns "[1,2]".
I try to re-do the above conditionals with hasOwnProperty
and in
methods, and they all return false.
Any ideas what might work here?