The React SDK enables you to use hooks to retrieve the user’s theme preferences.
Getting Started
1. Install the SDK
Install the SDK with your preferred package manager.
2. Wrap Your App with the Provider
Wrap your application with the UserPreferencesProvider component.
For local development, use the sandbox feature to test different theme preferences:
The sandbox prop should only be used for local development. Make sure to remove it before deploying to production. In production, theme preferences are controlled by the user through the Microapp platform.
3. Access Theme Preferences
Use the useUserPreferences hook to access the user’s theme preference.
The theme preference is controlled by the user through the Microapp platform. Your application should respect this preference and adapt accordingly.
4. Create and Apply Theme Styles
Define your theme styles in separate files and apply them based on the user’s theme preference.
1. For Microapp UI and Tailwind Apps
For Microapp UI and Tailwind CSS apps, we recommend using next-themes to handle theme application:
Configure your Tailwind setup to work with next-themes:
Then integrate next-themes with your Microapp preferences:
Or you can set up a two-way sync to update Microapp when the theme changes locally:
Then your components can use the theme-based classes:
2. For CSS-in-JS Libraries
For styled-components, emotion, or other CSS-in-JS libraries:
3. For CSS Variables
For applications using CSS variables:
You can then use these styles in your components: