|
|
@@ -5,16 +5,14 @@ import {createContext} from 'use-context-selector';
|
|
|
// #region 整体弹窗管理
|
|
|
type State = {
|
|
|
name: string;
|
|
|
- onClose: null | (() => void);
|
|
|
};
|
|
|
|
|
|
type Action =
|
|
|
| {type: 'SEARCH', payload: Pick<State, 'name'>}
|
|
|
-| {type: 'RESET'}
|
|
|
-| {type: 'SET_CLOSE', payload: State['onClose']};
|
|
|
+| {type: 'RESET'};
|
|
|
|
|
|
-function initState(onClose?: () => void): State {
|
|
|
- return {name: '', onClose: onClose ?? null};
|
|
|
+function initState(): State {
|
|
|
+ return {name: ''};
|
|
|
}
|
|
|
|
|
|
function reducer(state: State, action: Action): State {
|
|
|
@@ -23,8 +21,6 @@ function reducer(state: State, action: Action): State {
|
|
|
switch (type) {
|
|
|
case 'SEARCH':
|
|
|
return {...state, ...action.payload};
|
|
|
- case 'SET_CLOSE':
|
|
|
- return {...state, onClose: action.payload};
|
|
|
case 'RESET':
|
|
|
return initState();
|
|
|
default:
|
|
|
@@ -32,8 +28,8 @@ function reducer(state: State, action: Action): State {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export function useContextReducer(onClose: () => void) {
|
|
|
- return useReducer(reducer, initState(onClose));
|
|
|
+export function useContextReducer() {
|
|
|
+ return useReducer(reducer, initState());
|
|
|
}
|
|
|
|
|
|
export const context = createContext<[State, Dispatch<Action>]>([initState(), () => null]);
|