Skip to content

Commit 5fd1ed9

Browse files
authored
feat: add a useCSS hook (#13)
1 parent f856fcb commit 5fd1ed9

File tree

6 files changed

+816
-792
lines changed

6 files changed

+816
-792
lines changed

README.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ const Heading = () => {
7171

7272
### Hooks
7373

74-
| Hook | Description |
75-
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
76-
| [`useGlobal()`](#useglobal) | A hook for inserting transient global styles into the DOM. These styles will be injected when the hook mounts and flushed when the hook unmounts. |
77-
| [`useTokens()`](#usetokens) | A hook for inserting transient CSS tokens into the DOM. These tokens will be injected when the hook mounts and flushed when the hook unmounts. |
78-
| [`useThemes()`](#usethemes) | A hook for inserting transient CSS theme tokens into the DOM. These tokens will be injected when the hook mounts and flushed when the hook unmounts. |
74+
| Hook | Description |
75+
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
76+
| [`useCSS()`](#usecss) | A hook for [performantly and reliably](https://github.com/reactwg/react-18/discussions/110) inserting CSS into the DOM in React 18 using the `useInsertionEffect` hook. |
77+
| [`useGlobal()`](#useglobal) | A hook for inserting transient global styles into the DOM. These styles will be injected when the hook mounts and flushed when the hook unmounts. |
78+
| [`useTokens()`](#usetokens) | A hook for inserting transient CSS tokens into the DOM. These tokens will be injected when the hook mounts and flushed when the hook unmounts. |
79+
| [`useThemes()`](#usethemes) | A hook for inserting transient CSS theme tokens into the DOM. These tokens will be injected when the hook mounts and flushed when the hook unmounts. |
7980

8081
### Server rendering
8182

@@ -134,6 +135,44 @@ export const App = () => {
134135

135136
---
136137

138+
### useCSS()
139+
140+
A hook for [performantly and reliably](https://github.com/reactwg/react-18/discussions/110) inserting CSS into the DOM in React 18 using the
141+
`useInsertionEffect` hook.
142+
143+
#### Example
144+
145+
[Play with an example on **CodeSandbox**](https://codesandbox.io/s/dash-ui-react-usecss-example-gi3o6o)
146+
147+
```tsx
148+
import * as React from "react";
149+
import { createStyles } from "@dash-ui/styles";
150+
import { useGlobal } from "@dash-ui/react";
151+
152+
const styles = createStyles();
153+
154+
const Component = () => {
155+
const classes = useCSS(styles, {
156+
root: styles.one({ display: "flex", gap: "2rem" }),
157+
});
158+
159+
return (
160+
<div className={classes.root}>
161+
<div>Hello</div>
162+
<div>World</div>
163+
</div>
164+
);
165+
};
166+
```
167+
168+
#### Returns
169+
170+
```typescript
171+
Record<ClassNames, string>;
172+
```
173+
174+
---
175+
137176
### useGlobal()
138177

139178
A hook for inserting transient global styles into the DOM. These styles will be

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"devDependencies": {
4444
"@commitlint/cli": "^9.0.1",
4545
"@commitlint/config-conventional": "^9.0.1",
46-
"@dash-ui/styles": "^1.0.1",
46+
"@dash-ui/styles": "^1.1.1",
4747
"@semantic-release/changelog": "^6.0.0",
4848
"@semantic-release/git": "^10.0.0",
4949
"@swc-node/core": "^1.6.0",

0 commit comments

Comments
 (0)