Skip to content

Instantly share code, notes, and snippets.

@brian-lim-42
Created January 5, 2021 17:08
Show Gist options
  • Save brian-lim-42/b4e035a974bbdd91926f80151c6bcd40 to your computer and use it in GitHub Desktop.
Save brian-lim-42/b4e035a974bbdd91926f80151c6bcd40 to your computer and use it in GitHub Desktop.
Dynamic Global Store
import { makeVar } from '@apollo/client';
// could strongly type here
// leaving it dynamic for general use
type Store = { [key: string]: any }
const store: Store = {}
export const add = (key: string) => {
store[key] = makeVar(key);
}
export const set = (key: string, value: any) => store[key](value);
export const get = (key: string) => store[key]();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment