Skip to content

Commit

Permalink
[core] Fix typo in useLocalStorageState (#44024)
Browse files Browse the repository at this point in the history
Co-authored-by: hieuzeta <hieu@zetamotion.com>
  • Loading branch information
hieunguyenduc696 and hieuzeta authored Oct 6, 2024
1 parent 8a75a34 commit 755f394
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ function emitCurrentTabStorageChange(key: string) {
}
}

function subscribe(area: Storage, key: string | null, callbark: () => void): () => void {
function subscribe(area: Storage, key: string | null, callback: () => void): () => void {
if (!key) {
return () => {};
}
const storageHandler = (event: StorageEvent) => {
if (event.storageArea === area && event.key === key) {
callbark();
callback();
}
};
window.addEventListener('storage', storageHandler);
onCurrentTabStorageChange(key, callbark);
onCurrentTabStorageChange(key, callback);
return () => {
window.removeEventListener('storage', storageHandler);
offCurrentTabStorageChange(key, callbark);
offCurrentTabStorageChange(key, callback);
};
}

Expand Down Expand Up @@ -111,7 +111,7 @@ function useLocalStorageStateBrowser(
const [initialValue] = React.useState(initializer);
const area = window.localStorage;
const subscribeKey = React.useCallback(
(callbark: () => void) => subscribe(area, key, callbark),
(callback: () => void) => subscribe(area, key, callback),
[area, key],
);
const getKeySnapshot = React.useCallback(
Expand Down

0 comments on commit 755f394

Please sign in to comment.