Home > OS >  React cant read my argument inside my .map
React cant read my argument inside my .map

Time:01-06

I have another data folder with nested objects inside arrays I want to access them with .map function. Its working perfectly fine with divs and h3 but when it comes to this it says y is not defined

import Nav from './Nav'
import Cards from './Cards'
import data from './data'

export default function App(){

    return  ( data.map(y =>
        <Nav />,
        <Cards
        title = {y.title} // y is not recognized
        />
     ) )
}

CodePudding user response:

You need to add brackets:

return  ( data.map(y => (
    <>
<Nav />
    <Cards
    title = {y.title} 
    />
</>
) ) )
  • Related