Registry / web-framework / react-fela

react-fela

JSON →
library12.2.1jsnpmunverified

react-fela provides the official React bindings for the Fela dynamic styling library. It facilitates CSS-in-JS styling within React applications, leveraging Fela's core capabilities for atomic CSS generation, performance optimization, and server-side rendering. The current stable version is 12.2.1, with a consistent release cadence that includes minor feature additions, TypeScript improvements, and bug fixes across patch versions. Key differentiators include its focus on a functional, atomic CSS approach, robust plugin system (enhanced with context-free plugins in v12), and efficient rehydration mechanisms. It assumes familiarity with the core Fela library for its effective use within a React ecosystem.

npm install react-fela
INSTALL
IMPORT
SIG · REACT-FELA
R
react-fela
web-frameworkjavascriptv12.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useFela
import { useFela } from 'react-fela'
import useFela from 'react-fela'
A named export hook for functional components to access the renderer and theme context. Used extensively in modern React Fela applications.
RendererProvider
import { RendererProvider } from 'react-fela'
const { RendererProvider } = require('react-fela')
Required to provide the Fela renderer instance to the entire React component tree. CommonJS `require` is generally discouraged due to ecosystem shift to ESM.
ThemeProvider
import { ThemeProvider } from 'react-fela'
import { ThemeProvider as FelaThemeProvider } from 'react-fela'
Used to pass a theme object down the React tree via context. While aliasing is not inherently wrong, it's not the default usage.
createRenderer
import { createRenderer } from 'fela'
import { createRenderer } from 'react-fela'
The `createRenderer` function comes directly from the core `fela` package, not `react-fela` itself. This is a common mis-import.

This quickstart demonstrates the basic setup of Fela with React using the `useFela` hook, `RendererProvider`, and `ThemeProvider` to apply dynamic styles and theme values in a functional component.

import { createRenderer } from 'fela'; import { RendererProvider, ThemeProvider, useFela } from 'react-fela'; import { useState } from 'react'; const renderer = createRenderer(); const theme = { primary: 'blue', secondary: 'green', spacing: 16, }; type ButtonProps = { onClick: () => void; children: React.ReactNode; }; const Button: React.FC<ButtonProps> = ({ onClick, children }) => { const { css } = useFela((props: { primaryColor: string }) => ({ button: { backgroundColor: props.primaryColor, color: 'white', padding: `${theme.spacing / 2}px ${theme.spacing}px`, borderRadius: '4px', border: 'none', cursor: 'pointer', fontSize: '16px', '&:hover': { opacity: 0.8, }, }, })); return ( <button className={css('button', { primaryColor: theme.primary })} onClick={onClick}> {children} </button> ); }; const App: React.FC = () => { const [count, setCount] = useState(0); return ( <RendererProvider renderer={renderer}> <ThemeProvider theme={theme}> <div style={{ fontFamily: 'sans-serif', padding: theme.spacing }}> <h1>Fela with React Example</h1> <p>Count: {count}</p> <Button onClick={() => setCount(prev => prev + 1)}>Increment</Button> <div className={useFela(() => ({ marginTop: theme.spacing, color: theme.secondary, fontSize: '14px' }))().css({})}> Styled with `useFela` hook directly on a div. </div> </div> </ThemeProvider> </RendererProvider> ); }; export default App;
Debug
Known issues
breakingFela v12 introduced significant architectural changes, including a new context-free plugin concept and rehydration improvements. This requires migration for applications upgrading from Fela v11 or earlier.
fix
Consult the official Fela v12 migration guide (fela.js.org/docs/latest/extra/migration) for detailed steps and necessary code adjustments.
affects: >=12.0.0
gotchaFela v12.0.0 had a bug that accidentally passed an extra `theme` attribute to elements, potentially causing unexpected behavior or rendering issues. This was addressed in a hotfix.
fix
Upgrade to `react-fela@12.0.1` or higher to resolve the accidental `theme` attribute passing.
affects: 12.0.0
breakingPrior to Fela v11.6.0, the `RendererProvider` component had a `Children.only` restriction, meaning it could only accept a single child. This could lead to runtime errors if multiple children were provided.
fix
Upgrade to `react-fela@11.6.0` or higher to remove this restriction, or ensure `RendererProvider` only wraps a single child element (e.g., a `Fragment` or `div`).
affects: <11.6.0
gotchaEnsure `fela` is installed as a direct dependency or peer dependency that satisfies the `react-fela` version requirements. `react-fela` provides bindings, but the core Fela library is essential for styling to function.
fix
Run `npm install fela` or `yarn add fela` and verify its version matches the peer dependency requirement in `react-fela`'s `package.json`.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Fela renderer not found. Make sure to wrap your application with `RendererProvider`.
The Fela renderer instance was not provided to the React component tree via the `RendererProvider`.
fix
Wrap your root component or the section using Fela styles with `<RendererProvider renderer={myRendererInstance}>...</RendererProvider>`.
TypeError: Cannot read properties of undefined (reading 'theme')
A component attempted to access `theme` from the Fela context, but `ThemeProvider` was not used or the theme object was not provided.
fix
Ensure your components are wrapped with `<ThemeProvider theme={myThemeObject}>...</ThemeProvider>` and that `myThemeObject` is a valid theme object.
Module not found: Can't resolve 'fela' in '.../node_modules/react-fela/lib'
The core `fela` package, a peer dependency of `react-fela`, is not installed or cannot be resolved by the module bundler.
fix
Install the core Fela package by running `npm install fela` or `yarn add fela`.
Upgrade
Version history
12.2.1latest on npm
Audit
Dependencies
felarequiredCore Fela renderer library required for all Fela operations.
reactrequiredReact framework is required as this package provides React bindings.
Agent activity
4 hits · last 30 days
node
4
Resources
react-fela — npm install react-fela · libregistry