diff --git a/.github/workflows/release-package.yml b/.github/workflows/release-package.yml index 79806c9..e42889d 100644 --- a/.github/workflows/release-package.yml +++ b/.github/workflows/release-package.yml @@ -3,7 +3,7 @@ name: A Package for Utilities Functions and Hooks on: push: branches: - - main + - master jobs: build: diff --git a/README.md b/README.md index 0bfecb0..ce947db 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,67 @@ -# Vue 3 + TypeScript + Vite +# useWatchStorage Hook -This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 ` + + + +``` + +## Behavior + +- On component mount, the hook retrieves the stored value from the browser storage if available, falling back to the provided initialValue. +- Changes to the stored value are automatically synchronized with the browser storage. +- If changes are made in another tab or window, the hook listens for storage events and updates the stored value accordingly. +- The hook also includes a fallback mechanism to watch for changes within the same tab via a requestAnimationFrame loop. + +## Error Handling + +- If errors occur during storage operations (e.g., parsing JSON), appropriate error messages are logged to the console. +- Optionally, the hook can revert to the initial value in case of errors. + +## Dependencies + +@vue/reactivity: For reactive state management in Vue. +lodash: For utility functions such as deep equality comparison. + +## Notes + +Avoid using setInterval for watching storage changes, as it may consume excessive resources and slow down the browser. diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..b7744d3 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,3 @@ +import { useWatchStorage } from "./utils/use-watch-storage" + +export { useWatchStorage }