mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-08-28 17:26:47 +08:00
update: hooks, web
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { useCallback } from 'react'
|
||||
import { atom, useSetAtom, useAtomValue } from 'jotai'
|
||||
import type { PullOptions } from '@remake/core'
|
||||
|
||||
export interface Config {
|
||||
pick: number
|
||||
pull: PullOptions
|
||||
points: number
|
||||
allocate: number
|
||||
mode: number
|
||||
}
|
||||
|
||||
export const configAtom = atom<Config | null>(null)
|
||||
|
||||
export const useConfigInject = () => {
|
||||
const setConfig = useSetAtom(configAtom)
|
||||
return useCallback((config: Config) => setConfig(config), [setConfig])
|
||||
}
|
||||
|
||||
export const useConfig = () => {
|
||||
const config = useAtomValue(configAtom)
|
||||
if (!config) throw new Error('Game config is not set')
|
||||
return config
|
||||
}
|
||||
Reference in New Issue
Block a user