nanostores hook & upload btn

This commit is contained in:
grngxd 2025-06-08 13:07:24 +01:00
parent 7edcd0a49c
commit d792cec873
5 changed files with 58 additions and 5 deletions

17
src/hooks/nanostores.ts Normal file
View file

@ -0,0 +1,17 @@
import { isServer, noSerialize, useSignal, type NoSerialize } from '@builder.io/qwik';
import type { ReadableAtom } from 'nanostores';
export function useNanostore<T>(atom: ReadableAtom<T>) {
if (isServer) return
const state = useSignal<T>(atom.get());
const store = useSignal<NoSerialize<ReadableAtom<T>> | undefined>(undefined);
store.value = noSerialize(atom);
const unsubscribe = atom.subscribe((value) => {
state.value = value;
});
window.addEventListener('beforeunload', () => unsubscribe());
return state;
}