Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hazae41 committed Aug 28, 2022
1 parent 042f6cf commit 2b98de9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/mods/storages/local/async.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { useRef } from "react"
import { AsyncStorage, State } from "../storage"

/**
* Asynchronous local storage
*
* Use for compatibility with SSR
* Use for storing large objects
*
* Won't display data on first render or hydratation, you can either:
* - use SyncLocalStorage
* - use useFallback
*
* @see SyncLocalStorage
* @see useFallback
*/
export function useAsyncLocalStorage() {
const storage = useRef<AsyncLocalStorage>()

Expand All @@ -10,6 +23,19 @@ export function useAsyncLocalStorage() {
return storage.current
}

/**
* Asynchronous local storage
*
* Use for compatibility with SSR
* Use for storing large objects
*
* Won't display data on first render or hydratation, you can either:
* - use SyncLocalStorage
* - use useFallback
*
* @see SyncLocalStorage
* @see useFallback
*/
export class AsyncLocalStorage implements AsyncStorage<State> {
readonly async = true

Expand Down
20 changes: 20 additions & 0 deletions src/mods/storages/local/sync.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { useRef } from "react"
import { State, SyncStorage } from "../storage"

/**
* Synchronous local storage
*
* Do NOT use with SSR, it will create hydratation errors
* Do NOT use for storing large objects, it will harm performances
*
* Will display data on first render
*
* @see AsyncLocalStorage
*/
export function useSyncLocalStorage() {
const storage = useRef<SyncLocalStorage>()

Expand All @@ -10,6 +20,16 @@ export function useSyncLocalStorage() {
return storage.current
}

/**
* Synchronous local storage
*
* Do NOT use with SSR, it will create hydratation errors
* Do NOT use for storing large objects, it will harm performances
*
* Will display data on first render
*
* @see AsyncLocalStorage
*/
export class SyncLocalStorage implements SyncStorage<State> {
readonly async = false

Expand Down

0 comments on commit 2b98de9

Please sign in to comment.