React
Add theme state and controls to a client-rendered React app.
Install
Install the runtime in your existing React app. Keep your current styling system.
Add the provider
Wrap the part of your app that needs theme state. Register every palette key that your CSS defines.
Change the theme
Call the hook inside the provider. Pass the clicked element to anchor an animated transition.
Use setTheme for an immediate change. Use switchColorTheme to change a registered palette. theme stores the preference; resolvedTheme is light or dark.
Add styles and controls
Define your light, .dark, and .theme-caffeine styles. Follow Tailwind and palette setup when using registry controls.
For editable controls, preview the installation first:
For Vite, place the provider around your root app in src/main.tsx. For server rendering, use the Next.js or TanStack Start guide.
Example
See the React controls in the Next.js example. These controls use the same React hook. The complete app uses the Next.js provider described in its guide.

