Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda