0

Is there a way to render only some components in Reactjs

class UserproPage extends Component{

    render(){
        return(
        <>                 
             <Topbar/>
             <Navbar/>
             <div>
              <h1>Hello</h1>
             </div>
        </>
        )
    }

The <Navbar/> has menu button that are common to all the pages hence I do not want it to render them every time I click on links on the menu.

3

1 Answer 1

0

you can make a condition in your <Navbar/> component whether you display or not the menu button example :

class Navbar extends Component {

let display = true;

  render() {
    return (
      <div>This is my component.</div>
      {display && <button>menu</button>}
    );
  }
}

the menu button is displayed only when display variable is true

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.