Skip to content

Instantly share code, notes, and snippets.

@NoriSte
Last active October 12, 2020 06:45
Show Gist options
  • Save NoriSte/85520178804b9a1392d8521f42f81f8d to your computer and use it in GitHub Desktop.
Save NoriSte/85520178804b9a1392d8521f42f81f8d to your computer and use it in GitHub Desktop.
Re-implementing Recoil APIs / article gists
// @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