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

223
Visualizações
Hide Header and Footer for specific Components in React JS

I am working on react js project. I need to hide the header and footer for some specific components. I tried it with the following code snippet in the header component.

class Navbar extends Component {
state = {}
render() {
    const {user} = this.props;
    if (window.location.pathname === "/sign-in" || window.location.pathname === "/sign-up" || window.location.pathname === "/vehicles/reservation") return null;
    return (
        <header className="bg-gray-200 sticky z-50 h-20 md:h-auto top-0">...</header>);
    }
}

Since the render method is called only when there is a change, the above condition is not checked every time. How do I make a solution for this problem?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can pass a state variable as a props from parent component, for updating child component.

Parent componente:

state = {
    updateNavbar: false,
  }

//when is necessary update navbar:
this.setState(state => ({
      updateNavbar: !updateNavbar,
    }))

...
<Navbar updateNavbar={this.state.updateNavbar}>

about 4 years ago · Juan Pablo Isaza Relatório

0

If you want React to interact with the URL, you usually use a router. react-router is the popular one.

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