React Bulma Components
React Bulma Components is a library providing a comprehensive set of React components that directly implement the Bulma CSS framework, offering a declarative way to build user interfaces adhering to Bulma's design principles. The current stable version is 4.1.0, actively receiving patch and minor updates, with major versions (like v4.0.0) introducing significant breaking changes. Key differentiators include its compatibility across popular React frameworks such as Gatsby, Create React App, and Next.js. Since version 4, the library supports tree-shaking by default, optimizing bundle sizes. It also provides a unique `domRef` prop for passing refs to underlying DOM elements, bypassing React's `forwardRef` to reduce overhead in the React Dev Tools. Developers should note that some component APIs or naming conventions might diverge from official Bulma documentation, necessitating consultation of its Storybook documentation. The library expects Bulma CSS to be provided externally as a peer dependency, offering flexibility for custom SASS setups.
Common errors
-
Module not found: Can't resolve 'bulma/css/bulma.min.css'
cause The Bulma CSS framework is a peer dependency and must be installed and imported separately.fixRun `npm install bulma` or `yarn add bulma`, then add `import 'bulma/css/bulma.min.css';` to your application's entry point (e.g., `index.js` or `App.js`). -
TypeError: Cannot read properties of undefined (reading 'Input') (or similar for other Form sub-components)
cause Attempting to import Form sub-components (like Input, Field, Control) directly from 'react-bulma-components' instead of destructuring them from the 'Form' export.fixEnsure you import `Form` and then destructure its properties: `import { Form } from 'react-bulma-components'; const { Input, Field, Control, Label } = Form;` -
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
cause Using the standard `ref` prop on a `react-bulma-components` component, which internally expects `domRef` for passing refs to the actual DOM element.fixChange `ref={myRef}` to `domRef={myRef}` on the `react-bulma-components` component.
Warnings
- breaking Bulma CSS is no longer bundled with the library and has been moved to a peer dependency. You must install and import Bulma CSS separately in your project.
- breaking The `<List />` component has been completely removed in version 4.
- gotcha To pass a React ref to the underlying DOM element rendered by a `react-bulma-components` component, use the `domRef` prop instead of the standard `ref` prop. This is a deliberate design choice to avoid extra wrapper components from `React.forwardRef`.
- gotcha The API and naming conventions for components in `react-bulma-components` may sometimes differ from the official Bulma documentation. Always refer to the library's Storybook for accurate component usage and available props.
- breaking Version 4.0.0 introduced significant internal and external changes, including new spacing modifiers and improved TypeScript support, which may require adjustments to existing codebases. No official migration guide was provided.
Install
-
npm install react-bulma-components -
yarn add react-bulma-components -
pnpm add react-bulma-components
Imports
- Button
const Button = require('react-bulma-components').Button;import { Button } from 'react-bulma-components'; - Form.Input
import { Input } from 'react-bulma-components';import { Form } from 'react-bulma-components'; const { Input, Field } = Form; - Columns
import Columns from 'react-bulma-components/lib/components/Columns';
import { Columns } from 'react-bulma-components';
Quickstart
import React from 'react';
import 'bulma/css/bulma.min.css';
import { Button, Box, Section, Container } from 'react-bulma-components';
const App = () => {
return (
<Section>
<Container>
<Box>
<p className="title is-4">Welcome to React Bulma Components</p>
<Button color="primary" onClick={() => alert('Hello Bulma!')}>
Click Me
</Button>
{' '}
<Button color="link" renderAs="a" href="https://react-bulma.dev/" target="_blank" rel="noopener noreferrer">
Visit Docs
</Button>
</Box>
</Container>
</Section>
);
};
export default App;