声明:网上类似这种的应该很多,我这里只是项目用到,自己记录一下,方便以后遇到cv代码
定义初始数据
interface PointOfSaleFormFiberInitialStateType {
blocLevelList: CommonServersType.GetblocLevelListItem[]; // 列表
blocLevelLoading: boolean; // 是否加载
currPage: number; // 请求分页
total: number; // 列表总量
searchValue: string; // 输入框内容
}
const PointOfSaleFormFiberInitialState: PointOfSaleFormFiberInitialStateType = {
blocLevelList: [],
blocLevelLoading: false,
currPage: 1,
total: 0,
searchValue: '',
};
// 防抖需要的变量
let searchFlag: any = null;
下面是组件功能
// 自定义的hook,功能类似setState
const [state, setState] = useSetState(PointOfSaleFormFiberInitialState);
const { blocLevelList, currPage, total, blocLevelLoading, searchValue } = state;
// 获取列表
const getBlocLevelList = useCallback(
(_props: { page: number; list: any[]; value?: string }): any =