diff --git a/src/components/Stories/hooks/useSyncWithLS/README.md b/src/components/Stories/hooks/useSyncWithLS/README.md index db2c5788..a9ee3ce0 100644 --- a/src/components/Stories/hooks/useSyncWithLS/README.md +++ b/src/components/Stories/hooks/useSyncWithLS/README.md @@ -12,8 +12,9 @@ The `useSyncWithLS` hook executes callback when value changed in Local Storage ## Properties -| Name | Description | Type | Default | -| :------------- | :----------------------------------------------------------- | :------------: | :---------: | -| callback | Callback function called when key in local storage triggered | `VoidFunction` | | -| dataSourceName | Name for data source of keys | `string` | 'sync-tabs' | -| uniqueKey | Key in local storage for handle | `string` | | +| Name | Description | Type | Default | +| :----------------------- | :----------------------------------------------------------- | :------------: | :---------: | +| callback | Callback function called when key in local storage triggered | `VoidFunction` | | +| dataSourceName | Name for data source of keys | `string` | 'sync-tabs' | +| uniqueKey | Key in local storage for handle | `string` | | +| disableActiveTabCallback | Disable callback in tab that triggers local storage | `boolean` | 'false' | diff --git a/src/components/Stories/hooks/useSyncWithLS/useSyncWithLS.ts b/src/components/Stories/hooks/useSyncWithLS/useSyncWithLS.ts index f1cf39d5..5fdcdc40 100644 --- a/src/components/Stories/hooks/useSyncWithLS/useSyncWithLS.ts +++ b/src/components/Stories/hooks/useSyncWithLS/useSyncWithLS.ts @@ -4,6 +4,7 @@ export type UseSyncWithLSInputProps = { callback: T; uniqueKey: string; dataSourceName?: string; + disableActiveTabCallback?: boolean; }; export type UseSyncWithLSOutputProps = {callback: (...args: unknown[]) => void}; @@ -11,6 +12,7 @@ export const useSyncWithLS = ({ dataSourceName = 'sync-tabs', callback, uniqueKey, + disableActiveTabCallback = false, }: UseSyncWithLSInputProps): UseSyncWithLSOutputProps => { const key = `${dataSourceName}.${uniqueKey}`; @@ -34,7 +36,11 @@ export const useSyncWithLS = ({ return { callback: React.useCallback(() => { localStorage.setItem(key, String(Number(localStorage.getItem(key) || '0') + 1)); + + if (disableActiveTabCallback) { + return undefined; + } return callback(); - }, [key, callback]), + }, [key, disableActiveTabCallback, callback]), }; };