Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Component is undefined when using forwardRef and exported

I have an application that is written in Typescript, and uses Webpack with the ts-loader plugin to pack the application and serve it whilst running in dev mode.

I am trying to write a component in one file that is wrapped in React.forwardRef before being exported. I can create a component that works with React.forwardRef, but as soon as I export it I get an error saying that the value is undefined. I get this error regardless of whether I actually import the component in another file, or use it in the file it is defined in.

// This works fine
const Component = (props: any, ref: any) => <div ref={ref}>hello</div>
const ForwardedComponent = forwardRef(Component)
// This doesn't work:
const Component = (props: any, ref: any) => <div ref={ref}>hello</div>
export const ForwardedComponent = forwardRef(Component)
// Somehow this works!
const Component = (props: any, ref: any) => <div ref={ref}>hello</div>
const ForwardedComponent = forwardRef(Component)
export const ReExportedComponent = ForwardedComponent

The error I see when I try and export the component

Uncaught ReferenceError: ForwardedComponent is not defined

Any ideas what could be going on here?

Versions used:

"react": "^17.0.2",
"webpack": "^5.0.0",
"typescript": "^4.2.4",
"ts-loader": "8.3.0",
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda