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

125
Views
How to pass props down to child component in React

So in my main component, I send props to a child component like this:

<div className={styles.navBar}>
          <MasterNavBar color={false} scrollChange={true} />
</div>

MasterNavBar gets access to the props correctly, but I need MasterNavBar to pass those props to a child component called NavBar, which I currently do like this:

<NavBar props />

However, when I do this, the props are not accessible in my NavBar component file. For example, in NavBar, doing props.color to get my color prop returns undefined. So, am I passing my props incorrectly, or am I missing something else?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

That's depend on which props NavBar is expecting. If you don't care about typing (either with typescript or react PropTypes) you can simply do like this:

<NavBar {...props} />

However this is not the best approach and can lead to performance issues.

about 4 years ago · Juan Pablo Isaza Report

0

As Antonio Pantano said, you can pass the whole props to the <NavBar {...props}/> component, but this is a bad practice way. This article explained why it is a bad practice way. So you can pass the MasterNavBar props to its child in these two ways:

const MasterNavBar = (props) => {
 /* 
      rest of your code                    
*/ 

  return <NavBar color={props.color} scrollChange={props.scrollChange}/>

}

or

const MasterNavBar = ({color, scrollChange}) => {
 /* 
      rest of your code                    
*/ 
  return <NavBar color={color} scrollChange={scrollChange}/>

}

You can change the name of NavBar props as you wish, and you access them in the NavBar component by these names.

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!