@emotion/react downloads · last 12 months
@emotion/react is a React styling package for expressing CSS alongside React components. It addresses the work of associating styles with component output, letting developers define styles in JavaScript and apply them within a React application rather than maintaining every component’s styling in separate CSS files.
Its approach is CSS-in-JS: styles are written in the context of React and can be organized around the components that use them. The package is aimed at React developers who want styling to participate in component composition and reuse, while retaining the ability to describe styles with CSS-like properties and conventions.
The package provides the `css` prop as a way to attach styles to elements and components, and the `css` helper for defining reusable style objects. The `@emotion/react` API also includes `jsx` and `Global` for configuring JSX handling and applying global styles; the `ThemeProvider` and `useTheme` APIs support sharing theme values through the React tree. These patterns allow styles to be colocated, reused, or supplied through context.
Emotion is intended for React projects and fits workflows that use JavaScript or TypeScript component code, with Babel plugin support among its topics. Its APIs provide a path for teams to adopt component-scoped styling while still handling global rules and shared themes; JSX configuration may require attention to the project’s build setup when using the `css` prop.
The listed gzip bundle size is 12.1 kB, while the unpacked package size is 816.8 kB. Version 11.14.0 is MIT-licensed, with 7.3M weekly downloads and 18.0K GitHub stars; these figures indicate substantial ecosystem use, but they do not establish the runtime cost or suitability for a particular application. The package’s CSS-in-JS model also means styles are authored in JavaScript, which may not fit teams that prefer standalone stylesheets or CSS-first workflows.
- Use the `css` prop when styling React elements directly in component code and keeping styles near the markup they affect.
- Use the `css` helper when a style object needs to be reused across multiple React components.
- Use `ThemeProvider` and `useTheme` when React components need access to shared theme values through the component tree.
- Use `Global` when an application needs global CSS rules alongside component-level Emotion styles.
- Use Emotion’s JSX integration when a project wants the `css` prop to be handled as part of its React JSX workflow.
- Choose `@emotion/react` when a React team specifically wants a CSS-in-JS approach rather than keeping all styling in standalone stylesheets.
- Avoid `@emotion/react` when the project requires styling to remain in standalone CSS files; use a CSS-file workflow instead.
- Avoid the `css` prop if the build setup cannot support Emotion’s JSX handling; configure the JSX workflow or use conventional class names and stylesheets.
- Avoid CSS-in-JS if developers need to author styles without JavaScript; use a CSS-first approach that matches that constraint.
- Avoid `ThemeProvider` and `useTheme` when theme values do not need to flow through React context; define the required styles directly in the chosen styling system.
- Avoid adding Emotion solely to apply a small set of static rules; ordinary CSS classes can provide those styles without introducing this package’s styling API.
- Avoid relying on the 12.1 kB gzip figure as a guarantee of total application cost; measure the integrated build if bundle size is a release constraint.
CORRECTIONS
Spot wrong data here?Spot wrong data on this page?
A short note helps us fix it.A short note helps us fix it. We read every one; confirmed fixes ship in the next nightly build.
Anonymous · No account · No email back