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

329
Visualizações
Error. Error: Invalid hook call. Hooks can only be called inside of the body of a function component

I am creating a library of components. In this library, I created one component, connected it locally via npm link to my project, all work, the component was displayed. But when I decided to include styled-components to create a component. Here is my component.

import React, {FC} from 'react'
import styled from "styled-components"
import './mytbc.css'

export interface MyButtonProps{
    color:string;
    big?:boolean;
}

const MyCom: FC<MyButtonProps> = ({children,  color, big, ...props}) => {
    const MyCommon = styled.button`
        background:${color};
        padding:10px;
    `
    return (
        <MyCommon>
            {children}
        </MyCommon>
    )
}
export default MyCom

Then errors appeared in the console.

enter image description here

How to fix these errors and what are they related to?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I also had similar case when I was working with lerna and yarn workspaces. In my case the problem was using multiple and different versions of react, some where hoisted some were not during lerna compilation process.

According to docs

In order for Hooks to work, the react import from your application code needs to resolve to the same module as the react import from inside the react-dom package.

Run this command to list installed versions of react. And if you see more than one React, you’ll need to figure out why this happens and fix your dependency tree.

npm ls react

OR

yarn list react

Read more about the problem and solutions here

about 4 years ago · Juan Pablo Isaza Relatório
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