Jotai 試用紀錄
可取代 React Redux, State Managment, atomic.
應用方法
應用方法一:buttom-up
export const darkThemeAtom = atom<boolean>(false)
darkThemeAtom.debugLabel = 'meta/darkThemeAtom'
export const blockingAtom = atom<boolean>(false)
blockingAtom.debugLabel = 'meta/blockingAtom'
export const topAlertAtom = atom<ITopAlert | undefined>(undefined)
topAlertAtom.debugLabel = 'meta/topAlertAtom'
//-----------------------------------------------------------------------------
// derived atom / selector 群組的部份只提供讀取能力。
export const selectMeta = atom((get) => ({
darkTheme: get(darkThemeAtom).valueOf(),
blocking: get(blockingAtom).valueOf(),
topAlert: { ...get(topAlertAtom) }
}))
selectMeta.debugLabel = 'selectMeta';應用方法二:top-down
Jotai 重點指令介紹
基本指令
進階指令
useAtomCallback 練習用範例
兩招打天下: assignProps & assignValue
Last updated