Skip to main content
Works with
JSR Score
76%
Published
a month ago (0.0.2)

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

Add Package

deno add @bureaudouble-forks/react-style-singleton

Import symbol

import * as mod from "@bureaudouble-forks/react-style-singleton";

Add Package

npx jsr add @bureaudouble-forks/react-style-singleton

Import symbol

import * as mod from "@bureaudouble-forks/react-style-singleton";

Add Package

yarn dlx jsr add @bureaudouble-forks/react-style-singleton

Import symbol

import * as mod from "@bureaudouble-forks/react-style-singleton";

Add Package

pnpm dlx jsr add @bureaudouble-forks/react-style-singleton

Import symbol

import * as mod from "@bureaudouble-forks/react-style-singleton";

Add Package

bunx jsr add @bureaudouble-forks/react-style-singleton

Import symbol

import * as mod from "@bureaudouble-forks/react-style-singleton";