Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

534
Views
Problem while returning an array on react: Uncaught TypeError: Cannot read properties of undefined (reading 'items')

I am triying to return p in a div from an array that come from a useState hook, but give me this error:Uncaught TypeError: Cannot read properties of undefined (reading 'items')

Image

function App(){

        
    const [items, setLab] = useState(["a", "b", "c"])

    console.log(items)
    return (
        <div> laberinto
        {this.items.bind(this).map((item) => {
             <div>
                 <p>{item}</p> 
             </div>
         })
        }
        </div>
    )

}

 
render(
    <App/>,
    document.getElementById('app'),
);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your App component is a functional component (not a class component), so you don't need to use this keyword.

{items.map((item) => {
  <div>
    <p>{item}</p>
  </div>
 })
}

More detailed about Functional and Class components here: https://reactjs.org/docs/components-and-props.html#function-and-class-components

about 4 years ago · Juan Pablo Isaza Report

0

Issues

  1. this is simply undefined in React function components.
  2. Array.prototype.map callback needs to return a value being mapped to.

Solution

  • Remove any this references.
  • Return JSX from the .map callback. Don't forget to include the React keys.

Explicit return statement in the function body:

function App() {
  const [items, setLab] = useState(["a", "b", "c"]);

  return (
    <div>
      laberinto
      {items.map((item) => {
        return (
          <div key={item}>
            <p>{item}</p> 
          </div>
        );
      })}
    </div>
  );
}

Implicit return without a function body:

function App() {
  const [items, setLab] = useState(["a", "b", "c"]);

  return (
    <div>
      laberinto
      {items.map((item) => (
        <div key={item}>
          <p>{item}</p> 
        </div>
      ))}
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!