react-style-singleton

Just create a single stylesheet...

MIT 10 个版本
安装
npm install react-style-singleton
yarn add react-style-singleton
pnpm add react-style-singleton
bun add react-style-singleton
README

react-style-singleton

300b with all dependencies, minified and gzipped

Creates a style component with internal tracker.

  • Adds styles to the browser on the first instance mount.
  • Removes after the last instance unmount.
  • Thus helps you deliver styles you need to the customer, and clean up later.
  • Is not server-side rendering compatible!

API

Component

import {styleSingleton} from 'react-style-singleton'

const Style = styleSingleton();

export const App = () => (
  <Style styles={'body {color:red}'} />
);

Hook

import {styleHookSingleton} from 'react-style-singleton';

const useStyle = styleHookSingleton();
const useAnotherStyle = styleHookSingleton();

export const App = () => {
  useStyle('div {color:red}');
  useAnotherStyle('body { background-color:red }');
  return (<div />);
}

License

MIT

版本列表
2.2.3 2024-12-15
2.2.2 2024-12-15
2.2.1 2022-06-06
2.2.0 2022-04-17
2.1.1 2020-11-27
2.1.0 2020-04-16
2.0.0 2019-06-04
1.1.1 2019-01-20
1.1.0 2018-12-06
1.0.1 2018-06-07