question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import from 'flowbite-react' invalid hook call error

See original GitHub issue

Describe the bug When I import a component directly from flowbite-react such as the following:

import { Badge } from 'flowbite-react';

I receive an Invalid hook call error in the console and the page will not load.

However, if I run the following import, it works just fine:

import { Badge } from 'flowbite-react/lib/cjs/components/Badge';

Based on other examples I have seen, I don’t believe this is the intended use.

To Reproduce

  • Create a vite project with the react-ts template
  • Follow Flowbite/Flowbite-React quickstart guide for installation and configuration (installing the modules, updating `tailwind.config.js)
  • Import a component like mentioned above
  • Open up browser dev tools and verify the error

Expected behavior Import the component without errors

Screenshots image

System information:

  • Device: PC
  • Resolution: 1920x1080
  • OS: Windows 11
  • Browser: Edge
  • Version: v106.0.1370.42

Project information:

  • React / React-Dom: 18.2.0
  • Tailwind: 3.1.8
  • Flowbite: 1.5.3
  • Flowbite React: 0.2.0
  • Type: Vite, Turborepo

Additional Context I have attempted to import in multiple functional components from both a shared package and frontend app within my Turborepo project. Something as basic as:

import React from 'react';
import { Badge } from 'flowbite-react'; // this causes the invalid hook call error
// import { Badge } from 'flowbite-react/lib/cjs/components/Badge'; // this way works just fine

const TestComponent = () => {
  return (
    <>
      <Badge color='info'>Default</Badge>
    </>
  );
}

export default TestComponent;

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rluderscommented, Oct 15, 2022

I’m not seeing this part of the configuration in your project:

Nevermind, found it.

module.exports = {
    content: [
         'node_modules/flowbite-react/**/*.{js,jsx,ts,tsx}'
    ]
}
0reactions
rluderscommented, Oct 15, 2022

Well, it seems that it is not a flowbite-react bug… It is probably something specific from TurboRepo usage, but I never used it so I don’t know how to help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid Hook Call Warning - React
Invalid Hook Call Warning ... You are probably here because you got the following error message: Hooks can only be called inside the...
Read more >
Invalid hook call. Hooks can only be called inside of the body ...
You can only call hooks from React functions. ... For me , the error was calling the function useState outside the function default...
Read more >
Invalid hook call. Hooks can only be called inside of the body ...
Hi all, I am new to react and I am trying to create a react library of components and I came across this...
Read more >
Invalid hook call. Hooks can only be called inside of the body ...
Error : Invalid hook call. Hooks can only be called inside of the body of a function component. in my react native app...
Read more >
Error: Invalid hook call - Material Design for Bootstrap
In the package.json file remove react and react-dom dependencies. Now run npm install mdbreact; Import style files into the src/index.js before ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found