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

147
Views
JSX condition that does not work with React

I just started React and I'm facing a problem: when I run this piece of code, nothing is displayed.

const plantList = {
    name: 'monstera',
    category: 'classique',
    id: '1ed',
    isBestSale: true
};

function Notes(){
    plantList.map((plant) => (
    <li key={ plant.id }>
        {plant.isBestSale ? <span>๐Ÿ”ฅ</span> : <span>๐Ÿ‘Ž</span>}
    </li>
))}

export default Notes

Thank you in advance

about 4 years ago ยท Juan Pablo Isaza
2 answers
Answer question

0

plantList is an object, you probably want to put it in an array if you want to put multiple plants in it and have the ability to map over it.

const plantList = [{
  name: 'monstera',
  category: 'classique',
  id: '1ed',
  isBestSale: true
}];

You are not returning a value from your function component.

function Notes(){
return (
    <>
      {plantList.map((p) => (p.isBestSale ? <span>๐Ÿ”ฅ</span> : <span>๐Ÿ‘Ž</span>))}
    </>
  );
}
about 4 years ago ยท Juan Pablo Isaza Report

0

playlist is an object. But the object is not iterable in js. if you want to iterate you need to make it an array look like as

const plantList = [{
     name: 'monstera',
     category: 'classique',
     id: '1ed',
     isBestSale: true
 }];

you need to return anything from class/functional component to display

function Notes(){
     return (
     <>
       {plantList.map((p) => (p.isBestSale ? <span>๐Ÿ”ฅ</span> : <span>๐Ÿ‘Ž 
    </span>))}
   </>
)}

export default Notes

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!