Add useSetting and useSettingSetter hooks
Because `useSelector('getSetting')` and `useAction('setSetting')` dont have detailed type definitions for parameters and return. The type definitions for these two hooks are verbose but they ensure more type coverage and proper code auto-completion. [MAILPOET-2676]
This commit is contained in:
committed by
amine-mp
parent
9174df7323
commit
e617475803
17
assets/js/src/settings/store/hooks/useSetting.ts
Normal file
17
assets/js/src/settings/store/hooks/useSetting.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Settings } from '../types';
|
||||
import useSelector from './useSelector';
|
||||
|
||||
export function useSetting<Key1 extends keyof Settings>
|
||||
(key1: Key1): Settings[Key1];
|
||||
export function useSetting<Key1 extends keyof Settings, Key2 extends keyof Settings[Key1]>
|
||||
(key1: Key1, key2: Key2): Settings[Key1][Key2];
|
||||
export function useSetting<
|
||||
Key1 extends keyof Settings,
|
||||
Key2 extends keyof Settings[Key1],
|
||||
Key3 extends keyof Settings[Key1][Key2]>
|
||||
(key1: Key1, key2: Key2, key3: Key3): Settings[Key1][Key2][Key3];
|
||||
|
||||
export function useSetting(...path: string[]): any {
|
||||
const getValue = useSelector('getSetting');
|
||||
return getValue(path);
|
||||
}
|
Reference in New Issue
Block a user