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:
Amine Ben hammou
2020-03-05 01:08:59 +01:00
committed by amine-mp
parent 9174df7323
commit e617475803
4 changed files with 48 additions and 5 deletions

View 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);
}