Last active
October 12, 2020 06:45
-
-
Save NoriSte/85520178804b9a1392d8521f42f81f8d to your computer and use it in GitHub Desktop.
Re-implementing Recoil APIs / article gists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @see https://github.com/NoriSte/recoil-apis | |
export type Atom<T> = { key: string; default: T }; | |
export type Selector<T> = { | |
key: string; | |
get: ({ get }: { get: GetRecoilValue }) => T; | |
set?: ( | |
{ | |
get, | |
set | |
}: { | |
get: GetRecoilValue; | |
set: SetRecoilValue; | |
}, | |
nextValue: T | |
) => void; | |
}; | |
export type RecoilValue<T> = Atom<T> | Selector<T>; | |
/** | |
* Recoil id-free functions | |
*/ | |
type GetRecoilValue = <T>(recoilValue: RecoilValue<T>) => T; | |
type SetRecoilValue = <T>(recoilValue: RecoilValue<T>, nextValue: T) => void; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment