We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useState
useEffect
React 18 introduces useSyncExternalStore as a solution for this exact problem.
We should create new major version of react-use-svelte-store in favor of a version that uses the correct tool for the job.
This will involve some (very annoying) build configuration changes to support security enhancements for both major versions.
The text was updated successfully, but these errors were encountered:
please do :)
Sorry, something went wrong.
@Crisfole
Is this correct?
import { useSyncExternalStore } from 'react'; import { get, writable, readable, derived, Writable, Readable } from 'svelte/store'; export type Setter<T> = (v: T) => void; export type UpdateFn<T> = (v: T) => T; export type Updater<T> = (u: UpdateFn<T>) => void; export function useReadable<T>(store: Readable<T>): T { const subscribe = (listener: () => void) => { const unsubscribe = store.subscribe(listener); return unsubscribe; }; const getSnapshot = () => get(store); return useSyncExternalStore(subscribe, getSnapshot); } export function useWritable<T>(store: Writable<T>): [T, Setter<T>, Updater<T>] { const value = useReadable(store); return [value, store.set, store.update]; } // Re-export Svelte's implementations of the stores. export { get, writable, readable, derived, Writable, Readable };
I have genuinely no idea! :D If you test it, and it works, then yes!
With svelte 5 preferring runes to stores this library is becoming less and less needed.
@Crisfole Yes I tested on my website and it works. I am using Svelte 5 (they still not delete store yet) and using React 18.
No branches or pull requests
React 18 introduces useSyncExternalStore as a solution for this exact problem.
We should create new major version of react-use-svelte-store in favor of a version that uses the correct tool for the job.
This will involve some (very annoying) build configuration changes to support security enhancements for both major versions.
The text was updated successfully, but these errors were encountered: