Skip to content

Commit

Permalink
replace instance count of localstorage hook with useId
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantin-lukas committed Sep 12, 2024
1 parent 6dbc58b commit d31ee49
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "anzol",
"version": "2.5.0",
"version": "2.5.1",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Dispatch, SetStateAction } from "react";
import { useEffect, useState, useMemo } from "react";
import { useEffect, useState, useId } from "react";

export interface LocalStorageOptions {
/** If there is no value for the specified {@link key}, it automatically set this value on mount. */
Expand All @@ -13,8 +13,6 @@ export interface LocalStorageOptions {
listenForChanges?: boolean,
}

let instanceCount = 0;

/**
* Provides a wrapper around the localStorage API. Additionally, allows you to listen to changes between different
* instances of this hook. Other than that, it behaves mostly like a regular useState hook.
Expand Down Expand Up @@ -45,7 +43,7 @@ function useLocalStorage(key: string, {
return init;
});
const [blockUpdates, setBlockUpdates] = useState(true);
const id = useMemo(() => instanceCount++, []);
const id = useId();

useEffect(() => {
if (!blockUpdates) {
Expand Down

0 comments on commit d31ee49

Please sign in to comment.