import {createPageContext} from '@hooks'; import {Dispatch, useReducer} from 'react'; import {useLocation} from 'react-router-dom'; import {createContext} from 'use-context-selector'; // #region 查询条件 type State = { name: string; }; type Action = {type: 'SEARCH', payload: State} | {type: 'RESET'}; function reducer(state: State, action: Action): State { const {type} = action; switch (type) { case 'SEARCH': { return action.payload; } case 'RESET': return {name: ''}; default: return state; } } function initState(name?: string): State { return {name: name ?? ''}; } export function useContextReducer() { const {state} = useLocation(); return useReducer(reducer, initState(state?.name)); } export const context = createContext<[State, Dispatch]>([initState(), () => null]); // #endregion /** 页码管理 */ export const pageContext = createPageContext();