Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda