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

172
Views
How to hide null values during render in React?

I have this API endpoint:

GET https://xxx/xx

Result:

{
    "name": "Ana",
    "status": null,
}

I render the API result inside a blank page in my App and the page contains the following:

Ana
null

I want to hide null values.I don't want 'null' to be shown at all. How can I achieve this in React/Javascript?

{name && (
                <span>
                  {name}
                  <br />
                </span>
              )}
{status && (
                <span>
                  {status}
                </span>
              )}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

your code should work fine , I think you need to convert your api response to json.

Exemple

const response = await fetch(URL);
const jsonResponse = await response.json();
about 4 years ago · Juan Pablo Isaza Report

0

This is correct from what you have told me in the comments I think that you have some default value set for the response that status is a string. Please verify it.

const [status, setStatus] = useState<string | null>(null);
{status && (
                <span>
                  {status}
                </span>
              )}

when you are setting it with setStatus make sure that the value is not null like this

if (response.data.status) {
  setStatus(response.data.status)
} 
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!