Home > Mobile >  i want to display list of an array from react but it's not showing when i think i did everythin
i want to display list of an array from react but it's not showing when i think i did everythin

Time:11-13

i want to display list of an array from react but it's not showing when i think i did everything right? Please where im i wrong here

below is the code

import { useState } from 'react';

function App() {
   
  const [items , setItems] = useState([{
       id:1,
       text:'simple 1'
  },
  {
    id:1,
       text:'simple 2'
  },
  {
    id:1,
    text:'simple 3'
  },

])

  return (
    <div className="App">
    
    {items.map((item) => (
      <h1>{items.text}</h1>
    ))}


     <h1>Hello from React js</h1>
    </div>
  );
}

export default App;

CodePudding user response:

Because you're using items.text instead of item.text

{items.map((item) => (
  <h1>{item.text}</h1>
))}

Code its work perfectly

  • Related