const Chat = () => {
const [array1, setArray1] = useState(['one', 'two', 'three', 'four', 'five']);
const [array2, setArray2] = useState(['four', 'two']);
return (
<div>
<ul>
{array1.map((d) => {
return array2.forEach((e) => {
return d === e ? <li>{e}</li> : '';
});
})}
</ul>
</div>
);
};
export default Chat;
I expect my list items to render in order:
-"two"
-"four"
My logic, I will go through array1 and if I find matches from array2, then output them to the renderer. However, nothing comes to the render at all. Tell me what am I doing wrong?