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

301
Views
How to console.log() this function?

I'd like to generate JSX for React-Native, yet I do want to examine each key/value using console.log().

what I am after:

{Object.keys(this.state.types).map((obj) => (
          console.log(obj); <-- This guy
          <Item label={obj[TYPE]} value={obj[ID]} />
          ))}

But an Error is thrown "Unexpected token"

How can I still debug my values inside map?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use the comma operator:

 {Object.keys(this.state.types).map((obj) => (
      console.log(obj), <-- This guy
      <Item label={obj[TYPE]} value={obj[ID]} />
      ))}

Which evaluates the statement and then discards it, or you can use the || operator which will evaluate console.log which returns false and then will return the React element:

 {Object.keys(this.state.types).map((obj) => console.log(obj) || (

      <Item label={obj[TYPE]} value={obj[ID]} />
      ))}

However, both are fairly hacky, I recommend you turn your arrow function into a multi-line arrow and just use return:

 {Object.keys(this.state.types).map((obj) => { 
      console.log(obj);
      return <Item label={obj[TYPE]} value={obj[ID]} />
  })}

On a side note - don't forget to set the key property on your objects returned from an array or you'll get a performance slowdown and a warning (you're currently not doing this).

over 4 years ago · Santiago Trujillo Report

0

The round brackets in => ( tell the function that it's returning an object (JSX is transpiled into a JS object). You want a function body to run console.log(), and then return the <Item> element.

Convert the round brackets to curly ones, and add a return statement:

{Object.keys(this.state.types).map((obj) => {
  console.log(obj); <-- This guy
  return (
    <Item label={obj[TYPE]} value={obj[ID]} />
  );
})}
over 4 years ago · Santiago Trujillo 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!