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

No result when mapping an array of objects(React)

newbie here.

Cant seem to map the array below, which is the outcome of an axios fetch stored as "UserData.data".

(3) [{…}, {…}, {…}]
0: {_id: '6365763ec57b0ef06387f167', name: 'kalle', email: 'kalle@gmail.com', isAdmin: false, role: 'user', …}
1: {_id: '6365765dc57b0ef06387f16b', name: 'hasse', email: 'hasse@gmail.com', isAdmin: false, role: 'user', …}
2: {_id: '63657737c57b0ef06387f173', name: 'qwe', email: 'qwe@gmail.com', isAdmin: false, role: 'user', …}
length: 3
[[Prototype]]: Array(0)

Been trying this in my JSX, what im i doing wrong?

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

        <>
          <ul>
            {userData.data.map((data) => {
              <li key={data._id}>
                <Text>Test</Text>
              </li>
            })}
          </ul>
        </>
        <>
          <ul>
            {userData.data.map((data, i) => {
              <li key={data[i]}>
                <Text>Test</Text>
              </li>
            })}
          </ul>
        </>

>Solution :

You forgot to return the data

<>
  <ul>
    {userData.data.map((data) => {
      return (
        <li key={data._id}>
          <Text>Test</Text>
        </li>
      );
    })}
  </ul>
</>;

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