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

222
Views
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 answers
Answer question

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 Report

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 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!