Skip to content

Commit

Permalink
small hydration improvements (#47)
Browse files Browse the repository at this point in the history
* run onInit function when unmounting storage

* rename hydration flag

* fix formatting
  • Loading branch information
fa-sharp committed Oct 16, 2023
1 parent 282b946 commit da98f04
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useCallback, useEffect, useRef, useState } from "react"

import { BaseStorage, Storage, type StorageCallbackMap } from "./index"

type Setter<T> = ((v?: T, isHydrating?: boolean) => T) | T
type Setter<T> = ((v?: T, isHydrated?: boolean) => T) | T

/**
* isPublic: If true, the value will be synced with web API Storage
Expand Down Expand Up @@ -92,6 +92,9 @@ export const useStorage = <T = any>(rawKey: RawKey, onInit?: Setter<T>) => {
return () => {
isMounted.current = false
storageRef.current.unwatch(watchConfig)
if (onInit instanceof Function) {
setRenderValue(onInit)
}
}
}, [key, persistValue])

Expand Down

0 comments on commit da98f04

Please sign in to comment.