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

326
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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