Find the Component from a list of components that contains a certain class name. In my case i want to show the component that has the className "bbb". But I can't seem to find the className. In the code below i made my example with the Name of the component just so I can demonstrate better what i want to achieve:
import React, { useState, useEffect } from 'react';
const Test = () => {
const One = () => {
return (
<h1 className='aaa' >one</h1>
)
}
const Two = () => {
return (
<h1 className='bbb' >two</h1>
)
}
const Three = () => {
return (
<h1 className='ccc' >Three</h1>
)
}
const [data, setdata] = useState([<One />, <Two />, <Three />])
return (
<section>
{data.filter(x => x.type.name === 'One').map(x => {
// something like this line below. This doesn't work of course
// {data.filter(x => x.classList.contains('bbb)).map(x => {
return <div>{x}</div>
})}
</section>
)
};
export default Test;
I am really new to React js so sorry if this is a stupid question.
Edit: Fixed a typo