Created
March 30, 2023 17:54
-
-
Save JacobWeisenburger/68573d7b6c269d4fdfbd0a3fca1a0ba5 to your computer and use it in GitHub Desktop.
How to use some of Zustand in Deno Fresh
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
import { useSyncExternalStore } from 'https://esm.sh/[email protected]/compat' | |
import { createStore, StoreApi } from 'https://raw.githubusercontent.com/pmndrs/zustand/v4.3.6/src/vanilla.ts' | |
function useStore<State> ( store: StoreApi<State> ) { | |
return useSyncExternalStore( store.subscribe, store.getState ) | |
} | |
const store = createStore( () => ( { count: 0, foo: 'bar' } ) ) | |
export default function ZustandStore () { | |
const state = useStore( store ) | |
return <pre>{JSON.stringify( state )}</pre> /* {"count":0,"foo":"bar"} */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure if this will work for everything, but at first glance, this seems to work