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

129
Views
Passing props between siblings

i want to share props from components to sibling children. I've read about React Context but can't implement it.

My home component looks like this:

const Home = () => {
    return ( 
        <>
            <Navigation />
            <SearchBar />
            <Wrapper>
                <Filters />
                <ProductsList />
            </Wrapper>
        </>
     );
}

I have search state in SearchBar component, and need to pass it to ProductList component

const [search, setSearch] = useState('');

const handleSetSearch = (e) => {
    setSearch(e.target.value);
}

return ( 
    <Wrapper>
        <StyledTitle>inPal Search</StyledTitle>
        <InputWrapper>
            <StyledInput type="text" placeholder="Write something..." onChange={(e) => handleSetSearch(e)} />
            <SearchIcon src={searchIcon} alt="Search" />
        </InputWrapper>
    </Wrapper>
 );

Can someone help me to understand this?

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

0

You can declare the state in parent component (Home) and pass it as prop to both the child components as:

const Home = () => {

const [search, setSearch] = useState('');

return ( 
    <>
        <Navigation />
        <SearchBar search={search} setSearch={setSearch} />
        <Wrapper>
            <Filters />
            <ProductsList search={search} />
        </Wrapper>
    </>
 );
}
about 4 years ago · Juan Pablo Isaza Report

0

import React, { createContext } from "react";
import ProductsList from "./ProductsList";


const [search, setSearch] = useState('');

const handleSetSearch = (e) => {
    setSearch(e.target.value);
}
const Sr = createContext();


return ( 
    <Wrapper>
        <StyledTitle>inPal Search</StyledTitle>
        <InputWrapper>
            <StyledInput type="text" placeholder="Write something..." onChange={(e) => handleSetSearch(e)} />
            <SearchIcon src={searchIcon} alt="Search" />
        </InputWrapper>
<Sr.Provider value={search}>   
<ProductsList/>
</Sr.Provider>
 </Wrapper>
 );

ProductList
import React, { useContext } from "react";
import { Sr } from "./App";
const ProductList = () => {
    const sr = useContext(Sr);
    return <h1> your value is here {sr} </h1>
}
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!