Quickstart: React
1 Create the project
shellnpm create vite@latest css-hooks-playground -- --template react-ts cd css-hooks-playground
2 Install CSS Hooks
shellnpm install @css-hooks/react@next
3 Create the styling module
src/css.tsimport { createHooks, mergeStyles } from "@css-hooks/react"; export const { on, styleSheet } = createHooks("&:hover"); export { mergeStyles };
4 Render the stylesheet
src/main.tsximport { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import './index.css' import App from './App.tsx' +import { styleSheet } from './css' createRoot(document.getElementById('root')!).render( <StrictMode> + <style dangerouslySetInnerHTML={{ __html: styleSheet() }} /> <App /> </StrictMode>, )
5 Create a hover effect
Replace the contents of src/App.tsx with the following:
src/App.tsximport { on } from "./css"; export default function App() { return <button style={on("&:hover", { color: "red" })}>Hover me</button>; }
6 View the result
shellnpm run dev
By default, the development server is accessible at http://localhost:5173.
Next steps
Continue to Hooks and conditions to declare more hooks, then read Applying styles for composition patterns.