我正在react-router-dom@6.8.1与 一起使用redux-toolkit。我有一个典型的场景,我正在进行后端调用来获取数据(这发生在 RRD 提供的加载器函数内)。
获取数据后,我需要更新加载器函数内的 redux 状态。(这样,我可以避免useEffect在我的功能组件中出现另一个)。这是一个代码片段,可以让您更好地理解。
const router = createBrowserRouter([
{
path: "/",
errorElement: <Error />,
children: [
{
index: true,
element: <Home />,
loader: async () => {
try {
const response = await axios({
method: "get",
url: "some URL here",
});
// State update should happen here using dispatch. **********
return response;
} catch (e: any) {
throw json(
{ message: "Error occured while fetching data" },
{ status: e.status } …Run Code Online (Sandbox Code Playgroud) 它在 Android 模拟器上运行良好。但是当我构建 apk 文件并在我的 android 设备上运行它时,它只是卡在加载屏幕上。随意克隆 repo。
这是我上传的项目的链接 https://github.com/umakanth-pendyala/covid_19