• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rm-hull / use-local-storage / 18981841665

31 Oct 2025 06:32PM UTC coverage: 91.954% (+1.8%) from 90.123%
18981841665

push

github

web-flow
feat: Expose errors via state in `useLocalStorage` (#31)

* feat: Expose errors via state in useLocalStorage

This introduces explicit error reporting for storage operations
in `useLocalStorage`.

Instead of relying on silent `console.error` logging, storage
failures (serialization, deserialization, or storage access)
are now:

*   Wrapped in a custom `LocalStorageError` class.
*   Exposed via the new `error` property returned by the hook.

* fix: Clear error state upon successful read

Ensures that the internal error state is cleared if a successful
value read occurs (e.g., after an external update corrects a
previously corrupt entry).

Includes new tests verifying:
*   Error clearing behavior.
*   Error handling when the `serializer` fails during `setValue`.

* test: Improve error tests for useLocalStorage

Refactors existing error tests and adds coverage for failures
during the initial read phase (deserialization).

This ensures that when a custom serializer fails during
`deserialize`, the `useLocalStorage` hook correctly handles
the error:

*   Sets `result.current.error` to `LocalStorageError`.
*   Includes the underlying serialization error as the `cause`.
*   Keeps `result.current.value` as `undefined`.

* docs: Show error handling in README example

Added a demonstration of how to check for and render potential
`error` states returned by `useLocalStorage` within the Basic Counter
example.

Also reordered sections in the README for better content flow.

* docs: Add link to crypto-js in README

Adds a direct link to the recommended external
library `crypto-js` within the custom serializer
example section of the `README.md`.

21 of 26 branches covered (80.77%)

Branch coverage included in aggregate %.

59 of 61 relevant lines covered (96.72%)

46.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/src/useLocalStorage.ts


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc