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

207
Views
If statement in Jsx render based on data

Whats simplest way to write a if statement in jsx when its based on data your receiving

how can i check the other code at the same time-if that makes sense? so if its not "P" then i want to make sure the other value is deffo a "L"?

code = P so output “Walking” code = L so output "Running"

    text={
if(exercise.code = P)
{ "Walking"} 
else (exercise.code = L) 
{"Running"}} 
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

{
  exercise?.code === "P" ? "Walking" : exercise?.code === "L" ? "Running" 
  : null 
}

Here {} means you are in JS and can write if conditions. ? : is ternary operator.

about 4 years ago · Juan Pablo Isaza Report

0

{ exercise.code === "P" ? "Walking" : "Running" }
about 4 years ago · Juan Pablo Isaza Report

0

Create an object to use as a mapping:

const codeMap = {
  C: "Crawling",
  P: "Walking",
  L: "Running"
};

Then you can perform a lookup in your JSX:

... { codeMap[excercise?.code] || "Unknown/missing code" } ...

That will allow you to have as many codes as you want, and the JSX will not have to be changed.

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!