mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-08-29 10:04:43 +08:00
update: hooks, web
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { useCallback } from 'react'
|
||||
import { atom, useAtom, useSetAtom } from 'jotai'
|
||||
import type { ProfileState } from '@remake/core'
|
||||
|
||||
const profileAtom = atom<ProfileState | null>(null)
|
||||
|
||||
export const useProfile = () => {
|
||||
const [profile, setProfile] = useAtom(profileAtom)
|
||||
if (!profile) throw new Error('Profile is not loaded')
|
||||
return [profile, setProfile] as const
|
||||
}
|
||||
|
||||
export const useProfileInject = () => {
|
||||
const setProfile = useSetAtom(profileAtom)
|
||||
return useCallback(
|
||||
(profile: ProfileState) => setProfile(profile),
|
||||
[setProfile],
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user