leaky-ships/leaky-ships/hooks/useDrawProps.ts
2023-07-11 19:25:44 +02:00

40 lines
722 B
TypeScript

import { produce } from "immer"
import { create } from "zustand"
import { devtools } from "zustand/middleware"
const initialState: {
enable: boolean
shouldHide: boolean
color: string
} = {
enable: false,
shouldHide: false,
color: "#b32aa9",
}
export type State = typeof initialState
export type Action = {
setColor: (color: string) => void
reset: () => void
}
export const useDrawProps = create<State & Action>()(
devtools(
(set) => ({
...initialState,
setColor: (color) =>
set(
produce((state) => {
state.color = color
}),
),
reset: () => {
set(initialState)
},
}),
{
name: "gameState",
},
),
)