mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-28 17:18:46 +00:00
Wrap all JSON.parse calls with try-catch
This commit is contained in:
@@ -3,6 +3,7 @@ import { createContext } from 'preact'
|
||||
import { useCallback, useContext } from 'preact/hooks'
|
||||
import { useLocalStorage } from '../hooks/index.js'
|
||||
import type { Color } from '../Utils.js'
|
||||
import { safeJsonParse } from '../Utils.js'
|
||||
|
||||
interface Store {
|
||||
biomeColors: Record<string, [number, number, number]>
|
||||
@@ -19,7 +20,7 @@ export function useStore() {
|
||||
}
|
||||
|
||||
export function StoreProvider({ children }: { children: ComponentChildren }) {
|
||||
const [biomeColors, setBiomeColors] = useLocalStorage<Record<string, Color>>('misode_biome_colors', {}, JSON.parse, JSON.stringify)
|
||||
const [biomeColors, setBiomeColors] = useLocalStorage<Record<string, Color>>('misode_biome_colors', {}, s => safeJsonParse(s) ?? {}, JSON.stringify)
|
||||
|
||||
const setBiomeColor = useCallback((biome: string, color: Color) => {
|
||||
setBiomeColors({...biomeColors, [biome]: color })
|
||||
|
||||
Reference in New Issue
Block a user