You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ensure that you have initialized Palettez as per instructions under [Basic Usage](#basic-usage). As theme selection is only known on the client, you should only render component with `usePalettez` once the app has mounted.
213
+
214
+
```tsx
215
+
import*asReactfrom'react'
216
+
import { usePalettez } from'palettez/react'
217
+
218
+
function Component() {
219
+
const [mounted, setMounted] =useState(false)
220
+
221
+
useEffect(() => {
222
+
setMounted(true)
223
+
}, [])
224
+
225
+
returnmounted? <ThemeSelect /> :null
226
+
}
227
+
228
+
function ThemeSelect() {
229
+
const {
230
+
themesAndOptions,
231
+
themes,
232
+
setThemes,
233
+
234
+
getResolvedThemes,
235
+
restore,
236
+
sync,
237
+
subscribe,
238
+
} =usePalettez(window.palettez.getThemeStore())
239
+
240
+
returnthemesAndOptions.map((theme) => (
241
+
<divkey={theme.key}>
242
+
<labelhtmlFor={theme.key}>{theme.label}</label>
243
+
<select
244
+
id={theme.key}
245
+
name={theme.key}
246
+
onChange={(e) => {
247
+
setThemes({ [theme.key]: e.target.value })
248
+
}}
249
+
value={themes[theme.key]}
250
+
>
251
+
{theme.options.map((option) => (
252
+
<optionkey={option.key}value={option.key}>
253
+
{option.value}
254
+
</option>
255
+
))}
256
+
</select>
257
+
</div>
258
+
))
259
+
}
260
+
```
261
+
262
+
### Server-side persistence
263
+
264
+
If you are storing theme selection on the server, you can choose to use `memoryStorageAdapter` to avoid storing any data client-side. There's no need to initialize Palettez in a synchronous script. Ensure you pass the persisted theme selection when initializing Palettez as `initialThemes`.
0 commit comments