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

237
Views
How to pass a value to a React prop

I have a components: Header

const Header =()=>

{
return(
<div>

<h1> Top Header </h1>

</div>);

}

And 3 other components: C1, C2, C3.

What I want is to use the component Header as the header for all three components, but with different text in the tags for each component C1, C2, C3.

I tried passing it as props but didnt work out. e.g. as

const ProductsComponent =()=>
{
    return(
        <main className="products">
            <Header>Products</Header>
            <div className="content">
                
            </div>
            
        </main>
    );
};

How can I do it?

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

0

You are currently not passing any props to your Header component, you'd have to do it like this:

const ProductsComponent =()=>
{
    return(
        <main className="products">
            <Header tag="Products"/>
            <div className="content">
                
            </div>
            
        </main>
    );
};

Then you're Header component would have to look like this:

const Header =(props)=>

return(
<div>

<h1> Top Header </h1>
{props.tag}
</div>);

}

Or you could destructre tags out of your props like this:

const Header =({ tag })=>

return(
<div>

<h1> Top Header </h1>
{tag}
</div>);

}
about 4 years ago · Juan Pablo Isaza Report

0

You should write Header component like this

const Header =(props)=>{
return(<div>
           <h1> {props.children || 'Top Header'}</h1>
       </div>);
}
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!