SukkaW / foxact

React Hooks/Utils done right. For Browser, SSR, and React Server Components.
https://foxact.skk.moe
MIT License
316 stars 12 forks source link

useLocalStorage: Can the behavior value be `null` even when I set the initial value as expected? #18

Closed dinwwwh closed 4 months ago

dinwwwh commented 6 months ago
  const [manager, setManager] = useLocalStorage<'npm' | 'pnpm' | 'yarn'>('package-manager', 'pnpm')

Expected: manager cannot be null when I set initial value Actual: manager can be null

SukkaW commented 6 months ago
  const [manager, setManager] = useLocalStorage<'npm' | 'pnpm' | 'yarn'>('package-manager', 'pnpm')

Expected: manager cannot be null when I set initial value Actual: manager can be null

Here is the corrected and enhanced version of your statement:

Could you provide a minimal reproduction of the issue, either on CodeSandbox or StackBlitz? Without a minimal reproduction, I can't pinpoint the exact problem you're encountering.

dinwwwh commented 6 months ago
  const [manager, setManager] = useLocalStorage<'npm' | 'pnpm' | 'yarn'>('package-manager', 'pnpm')

Expected: manager cannot be null when I set initial value Actual: manager can be null

Here is the corrected and enhanced version of your statement:

Could you provide a minimal reproduction of the issue, either on CodeSandbox or StackBlitz? Without a minimal reproduction, I can't pinpoint the exact problem you're encountering.

I don't think we need a minimal reproduction, because this is actual current behavior of useLocalStorage hooks.

Can the behavior value be null even when I set the initial value as expected?

SukkaW commented 4 months ago

@dinwwwh I've improved the types of useLocalStorage in https://github.com/SukkaW/foxact/commit/3c4515e9cb5e6d7ac19cfe3ba157dd221409b076. Now when the serverValue is provided the state will not be null.