Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can I pass a value on reactjs within the map?

ola, will it be that has some way to pass AxiosComponent inside the map without it returns this error ?

My code:

musicTop.map((item, key)=>{
      <AxiosComponent titles={item.title} key={key} items={item.items} />
})

my error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.

>Solution :

The arrow function you’re providing to map doesn’t return anything.

Try one of these instead (they are both the same, just with slightly different syntax):

musicTop.map((item, key) => {
  // Here we add the `return` keyword that was missing in the original code
  return <AxiosComponent titles={item.title} key={key} items={item.items} />
})
// Here we use a shorthand form of the arrow function to return the component
musicTop.map((item, key) => <AxiosComponent titles={item.title} key={key} items={item.items} />)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading