Flowbite React
Flowbite React is an open-source library providing official React components built on top of the Flowbite design system and styled with Tailwind CSS utility classes. It aims to accelerate web development by offering a collection of pre-built, interactive UI components like buttons, modals, navigation bars, and forms. Currently at version 0.12.17, the library maintains an active development pace with frequent patch releases addressing bug fixes, performance improvements (e.g., recent bundle size reduction), and new features. Its key differentiators include being the official React implementation of Flowbite, deep integration with Tailwind CSS for customizable styling, and providing robust TypeScript support for enhanced developer experience. It targets React 18 and 19, and Tailwind CSS 3 and 4, ensuring compatibility with modern React ecosystems.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'tailwindConfig')
cause Flowbite React relies on a specific `tailwind.config.js` setup. This error often occurs when Tailwind CSS is not correctly configured or the `flowbite-react` plugin is missing from the config.fixEnsure `tailwind.config.js` exists and includes the `flowbite-react/plugin` in its plugins array. Run `npx flowbite-react@latest init` to automatically configure Tailwind CSS. -
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
cause This typically means a component was imported incorrectly (e.g., trying to default import a named export) or the component path is wrong, leading to `undefined` being rendered where a React component is expected.fixVerify that you are using named imports (e.g., `import { Button } from 'flowbite-react';`) for all Flowbite React components. Double-check component names and import paths for typos. -
Module not found: Error: Can't resolve 'flowbite-react'
cause The `flowbite-react` package is not installed or not correctly resolved by your module bundler.fixEnsure `flowbite-react` is listed in your `package.json` and installed (`npm install flowbite-react` or `yarn add flowbite-react`). Check your bundler configuration if it's a non-standard setup.
Warnings
- gotcha The README explicitly states, '⚠️ This is a pre-release version - please note that APIs may change before the final release'. This indicates potential instability and breaking changes before a 1.0.0 release.
- breaking Breaking changes related to Tailwind CSS v4 integration. If using Tailwind CSS v4, the configuration now automatically generates a v4 config file and uses CSS variables instead of inline colors for theming. This change is only applicable if you are upgrading to Tailwind CSS v4.
- gotcha The recent bundle size reduction from 42 MB to 8.38 MB (flowbite-react@0.12.17) was achieved by dropping AST parsers in favor of `oxc-parser` and migrating the bundler from `tsup` to `tsdown`. While this is a positive change, it implies significant underlying build tool changes that could potentially expose new edge cases or build environment incompatibilities.
Install
-
npm install flowbite-react -
yarn add flowbite-react -
pnpm add flowbite-react
Imports
- Button
import Button from 'flowbite-react';
import { Button } from 'flowbite-react'; - Modal
const Modal = require('flowbite-react').Modal;import { Modal } from 'flowbite-react'; - Flowbite
import { ThemeProvider } from 'flowbite-react';import { Flowbite } from 'flowbite-react'; - CustomFlowbiteTheme
import type { CustomFlowbiteTheme } from 'flowbite-react';
Quickstart
import { useState } from 'react';
import { Button, Modal, Flowbite } from 'flowbite-react';
import type { CustomFlowbiteTheme } from 'flowbite-react';
// Custom theme example for demonstration
const customTheme: CustomFlowbiteTheme = {
button: {
base: 'text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800'
},
modal: {
content: {
base: 'relative h-full w-full p-4 md:h-auto'
}
}
};
function App() {
const [openModal, setOpenModal] = useState(false);
return (
<Flowbite theme={{ theme: customTheme }}>
<div className="flex flex-col items-center justify-center min-h-screen p-4 bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white">
<h1 className="text-3xl font-bold mb-4">Welcome to Flowbite React!</h1>
<Button onClick={() => setOpenModal(true)}>Show Modal</Button>
<Modal show={openModal} onClose={() => setOpenModal(false)} popup>
<Modal.Header>Terms of Service</Modal.Header>
<Modal.Body>
<div className="space-y-6">
<p className="text-base leading-relaxed text-gray-500 dark:text-gray-400">
With less than a month to go before the European Union enacts new consumer privacy laws,
companies around the world are scrambling to update their data governance policies.
</p>
<p className="text-base leading-relaxed text-gray-500 dark:text-gray-400">
The European Union’s General Data Protection Regulation (GDPR) goes into effect on May 25,
2018, and is meant to ensure a common set of data rights in the European Union.
</p>
</div>
</Modal.Body>
<Modal.Footer>
<Button onClick={() => setOpenModal(false)}>I accept</Button>
<Button color="gray" onClick={() => setOpenModal(false)}>
Decline
</Button>
</Modal.Footer>
</Modal>
</div>
</Flowbite>
);
}
export default App;