UseSyncWebStorage()
useSyncExternalStore 의 wrapper 입니다. ReactSyncConnector
를 통해 외부 스토리지와 동기화를 합니다.
Signature
useSyncWebStorage: <T>(connector: ReactSyncConnector<T>) => NonNullable<T> | null
Parameters
Parameter | Type | Description |
---|---|---|
connector |
Returns
NonNullable<T> | null
Example
const textStorage = new SyncedStorage<string>("text", localStorage)
const textConnector = new ReactSyncConnector(textStorage)
textStorage.set("Hello, World!")
textStorage.set((prev) => prev + "!")
textStorage.get() // "Hello, World!!"
const text = useSyncWebStorage(textConnector)
console.log(text) // "Hello, World!!"