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

122
Views
Pasar accesorios entre hermanos.

quiero compartir accesorios de componentes a niños hermanos. He leído sobre React Context pero no puedo implementarlo.

El componente de mi hogar se ve así:

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

Tengo estado de búsqueda en el componente SearchBar y necesito pasarlo al componente ProductList

 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> );

¿Alguien puede ayudarme a entender esto?

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

0

Puede declarar el estado en el componente principal ( Home ) y pasarlo como apoyo a los componentes secundarios como:

 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!