在React / Redux中,如果一个函数组件正在使用redux-thunk调度一个函数,它可以通过以下步骤来设置isLoading状态:
- 首先,在函数组件中引入useState钩子,用于管理isLoading状态。例如:import { useState } from 'react';
- 在函数组件中使用useState钩子创建isLoading状态和对应的setter函数。例如:const [isLoading, setIsLoading] = useState(false);
- 在函数组件中使用redux-thunk调度一个函数时,可以在函数组件内部通过调用setIsLoading函数来设置isLoading状态。例如:dispatch(fetchData()).then(() => setIsLoading(false));
这样,当函数组件使用redux-thunk调度一个函数时,可以在函数组件内部通过调用setIsLoading函数来设置isLoading状态为true或false,以实现加载状态的控制。
关于React / Redux、redux-thunk的更多信息,可以参考以下链接:
- React官方文档:https://reactjs.org/
- Redux官方文档:https://redux.js.org/
- redux-thunk GitHub仓库:https://github.com/reduxjs/redux-thunk