# React Hooks 类型集
# Setter
// React.useState返回值的第二个元素的类型
type Setter<T> = Dispatch<SetStateAction<T>>;
# UseState
// React.useState的返回值
type UseState<T> = [T, Setter<T>];
# SoftStorage
type SoftStorage<T> = {
storage: Required<{ [K in keyof T]: StorageItem<T, K> }>;
storageHelper: StorageHelper;
itemStateDict: Record<keyof T, UseState<T[keyof T]>>;
properties: (keyof T)[];
};
Referenced Types
# SetterKey
type SetterKey<T> = PrefixedKey<T, 'set'>;
Referenced Types
# StorageState
type StorageState<T, K extends keyof T> = {
[Key in K]: T[K];
} & {
[Key in SetterKey<K>]: Setter<T[K]>;
} & {
[Key in ResetterKey<K>]: Resetter;
} & {
[Key in CheckerKey<K>]: Checker;
};
Referenced Types
# StateKey
type StateKey<T> = SuffixedKeys<T, 'state'>;
Referenced Types
# StorageStates
type StorageStates<T> = {
[SK in StateKey<T>]: RestoreSuffixedKey<SK, 'state'> extends keyof T
? StorageState<T, RestoreSuffixedKey<SK, 'state'>>
: never;
};