Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda