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

379
Views
No se puede encontrar el error 'ctx' del espacio de nombres al crear Contexto con reaccionar - mecanografiado

Estoy trabajando en un proyecto con react usando typescript y estoy pasando un mal momento para averiguar por qué ocurre este error, básicamente, no puedo usar ningún ejemplo createContext que encontré en Internet debido a esto. Este específicamente lo obtuve de aquí: https://github.com/typescript-cheatsheets/react-typescript-cheatsheet Estoy tratando de usar lo mismo que se muestra en la sección Contexto.

 import * as React from "react"; export function createCtx<A>(defaultValue: A) { type UpdateType = React.Dispatch<React.SetStateAction<typeof defaultValue>>; const defaultUpdate: UpdateType = () => defaultValue; const ctx = React.createContext({ state: defaultValue, update: defaultUpdate }); function Provider(props: React.PropsWithChildren<{}>) { const [state, update] = React.useState(defaultValue); return <ctx.Provider value={{ state, update }} {...props} />; } return [ctx, Provider] as [typeof ctx, typeof Provider]; }

El problema es que cada vez que dice que hay este error No se puede encontrar el espacio de nombres ctx en la línea:

 return <ctx.Provider value={{ state, update }} {...props} />;

Todavía no puedo entender por qué, ¿alguien puede ver si estoy haciendo algo mal aquí? Este es mi tsconfig.json:

 { "compilerOptions": { "target": "es5", "lib": [ "dom", "dom.iterable", "esnext" ], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "strict": false, "forceConsistentCasingInFileNames": true, "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "preserve", "noImplicitAny": false, "strictNullChecks": false }, "include": [ "src" ] }

¡Cualquier ayuda sería apreciada!

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Lo más probable es que la extensión de su archivo sea .ts en lugar de .tsx .

Por lo tanto, TypeScript interpreta <ctx.Provider como cast e intenta encontrar un Provider de tipo en el espacio de nombres ctx .

over 4 years ago · Santiago Trujillo Report

0

Utilice tsx en lugar de ts , tiene algunas diferencias mínimas. tsx obviamente permite el uso de etiquetas jsx dentro de mecanografiado.

over 4 years ago · Santiago Trujillo 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!