11import React from 'react' ;
22
33import { skipToken } from '@reduxjs/toolkit/query' ;
4- import { debounce } from 'lodash' ;
54
6- import type { SetSingleSettingParams } from '../../../types/api/settings' ;
75import { uiFactory } from '../../../uiFactory/uiFactory' ;
86import { useTypedDispatch } from '../../../utils/hooks/useTypedDispatch' ;
97import { useTypedSelector } from '../../../utils/hooks/useTypedSelector' ;
@@ -22,15 +20,11 @@ import {
2220
2321type SaveSettingValue < T > = ( value : T | undefined ) => void ;
2422
25- interface UseSettingOptions {
26- /** Time before setting will be set */
27- debounceTime ?: number ;
28- }
29-
30- export function useSetting < T > (
31- name ?: string ,
32- { debounceTime = 0 } : UseSettingOptions = { } ,
33- ) : { value : T | undefined ; saveValue : SaveSettingValue < T > ; isLoading : boolean } {
23+ export function useSetting < T > ( name ?: string ) : {
24+ value : T | undefined ;
25+ saveValue : SaveSettingValue < T > ;
26+ isLoading : boolean ;
27+ } {
3428 const dispatch = useTypedDispatch ( ) ;
3529
3630 const preventSyncWithLS = Boolean ( name && SETTINGS_OPTIONS [ name ] ?. preventSyncWithLS ) ;
@@ -80,23 +74,10 @@ export function useSetting<T>(
8074 }
8175 } , [ shouldUseMetaSettings , shouldUseOnlyExternalSettings , metaSetting , name , dispatch ] ) ;
8276
83- const debouncedSetMetaSetting = React . useMemo (
84- ( ) =>
85- debounce ( ( params : SetSingleSettingParams ) => {
86- setMetaSetting ( params ) ;
87- } , debounceTime ) ,
88- [ debounceTime , setMetaSetting ] ,
89- ) ;
90-
91- // Call debounced func on component unmount
92- React . useEffect ( ( ) => {
93- return ( ) => debouncedSetMetaSetting . flush ( ) ;
94- } , [ debouncedSetMetaSetting ] ) ;
95-
9677 const saveValue = React . useCallback < SaveSettingValue < T > > (
9778 ( value ) => {
9879 if ( shouldUseMetaSettings ) {
99- debouncedSetMetaSetting ( {
80+ setMetaSetting ( {
10081 user,
10182 name : name ,
10283 value : stringifySettingValue ( value ) ,
@@ -107,7 +88,7 @@ export function useSetting<T>(
10788 setSettingValueToLS ( name , value ) ;
10889 }
10990 } ,
110- [ shouldUseMetaSettings , shouldUseOnlyExternalSettings , user , name , debouncedSetMetaSetting ] ,
91+ [ shouldUseMetaSettings , shouldUseOnlyExternalSettings , user , name , setMetaSetting ] ,
11192 ) ;
11293
11394 return { value : settingValue , saveValue, isLoading} as const ;
0 commit comments