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

175
Views
TypeScript en el problema createContext

En mi aplicación tengo esto:

 const restaurantsArr = [{ name: McDonald, rating: 5 }] const RestaurantContext = createContext(); const [restaurants, setRestaurants] = useState(restaurantsArr);

Para Provider , quiero pasar mis variables desestructuradas de useState .

 <Provider value={[restaurants, setRestaurants]} />

TS me grita que createContext debe tener valor, pero si mi createContext tiene una matriz vacía, por ejemplo, tengo errores.

¿Cómo debo crear la interfaz ContextProps ?

De hecho, tengo una matriz que contiene otra matriz de objetos y una función.

Estoy luchando con esto por un par de horas y tengo advertencias y errores todo el tiempo...

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

0

Ok, entonces tengo esto ahora:

 export const RestaurantsContext = createContext<any>([]); interface Props { children: ReactElement; } const RestaurantsProvider: React.FC<Props> = ({children}) => { const [restaurants, setRestaurants] = useState(restaurantsArr) return ( <RestaurantsContext.Provider value={[restaurants, setRestaurants]}> {children} </RestaurantsContext.Provider> )

Pero es solo un paseo con cualquiera en export const RestaurantsContext = createContext<any>([]) .

Lo que quiero hacer es tener algo como:

 interface ContextProps { //and something here }

Pero, ¿cómo debo escribir [data, setData]? Es una matriz con una matriz de objetos y con la función setState.

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!