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

178
Views
React multi level if conditional rendering not working

I am using next.js and I have a page that renders a component.

export default function SamplePage() {
  return (
    <>
      {myData.map((countries) => {
        if (countries.title === "USA") {
          {
            countries.states.map((state) => {
              if (state.name === "NY") {
                console.log(state.name); // NY
                return <NYMap />;
              } elseif (state.name === "CA") {
                console.log(state.name); // Californima
                return <CaliforniaMap />;
              }
            });
          }
        }
      })}
    </>
  );
}

but I am not able to render <NYMap /> and <CaliforniaMap /> components. myData is passed correctly and using console log inside the if statements works just not displaying the component.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Without an explicit return in the outer map what was being implicitly returned was undefined and there was nothing to render.

Add a return statement to the states mapping:

return countries.states.map((state) => {
  if (state.name === "NY") {
     console.log(state.name); // NY
     return <NYMap />;
  } elseif (state.name === "CA") {
     console.log(state.name); // Californima
     return <CaliforniaMap />;
  }
});
about 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!