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

130
Views
¿Cómo agregar ```Context``` con rutas configuradas?

Quiero agregar el contexto searchContext en mi App.js para que mis componentes Navbar y Results tengan acceso a las variables que contiene. ¿Cómo haría esto con mis rutas configuradas? Intenté simplemente agregar con ellos, pero eso no funcionó. Este es el código.

 <Router> // Where does <searchContext.Provider> go? <Navbar></Navbar> <Routes> <Route exact path='/' element={<Home />} /> <Route path='/results'> <Route path='/results/:value' element={<Results />} /> {/*<Route path='/results/:value/:slot' element={<Slot />}*/} </Route> // Another route that has nothing to do with searchContext </Routes> </Router>

Editar: se agregó "// Otra ruta que no tiene nada que ver con searchContext"

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

0

si fuera usted, simplemente envolvería todo con el proveedor siempre que no sea demasiado pesado.

about 4 years ago · Juan Pablo Isaza Report

0

Hola, esto va con la comprensión general del contexto Api, ahora la estructura de sus carpetas es su elección, pero seré muy breve aquí

 //on your context file searchContext.js import {useState,createContext} from 'react'; export const SearchContext = createContext(null); export const ContextProvider = props => { const [search,setSearch] = useState(null); return <SearchContext.Provider value = {{search,setSearch}}> {children> </SearchContext.Provider> } //now on your route.js import { ContextProvider} from '../your/path/file'; .... <Router> // Where does <searchContext.Provider> go? <ContextProvider> <Navbar></Navbar> <Routes> <Route exact path='/' element={<Home />} /> <Route path='/results'> <Route path='/results/:value' element={<Results />} /> {/*<Route path='/results/:value/:slot' element={<Slot />}*/} </Route> // Another route that has nothing to do with searchContext </Routes> </ContextProvider> </Router>
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!