您正在使用遗留实现。请更新您的代码:使用createWrapper() 和wrapper.useWrappedStore()。 nextjs 还原?

2024-01-15

我在使用 redux 工具包和 next js 时遇到错误。我面临着这个遗留警告-

/!\ You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.useWrappedStore().

我不明白问题实际发生在哪里,我必须更新我的代码。

这是代码-

this is store.ts-

import { Action, configureStore, ThunkAction } from "@reduxjs/toolkit";
import { createWrapper, HYDRATE } from "next-redux-wrapper";
import { combinedReducer } from "./Reducer";

const reducer: typeof combinedReducer = (state, action) => {
    if (action.type === HYDRATE) {
        const nextState = {
            ...state,
            ...action.payload,
        };
        return nextState;
    } else {
        return combinedReducer(state, action);
    }
};

export const makeStore = () => configureStore({ reducer });

type Store = ReturnType<typeof makeStore>;

export type AppDispatch = Store['dispatch'];
export type RootState = ReturnType<Store['getState']>;
export type AppThunk<ReturnType = void> = ThunkAction<
    ReturnType,
    RootState,
    unknown,
    Action<string>
>;

export const wrapper = createWrapper(makeStore);

Here is reducer.ts-

import { combineReducers } from '@reduxjs/toolkit';

export const combinedReducer = combineReducers({
    //All reducer
});

Here is Hook.ts-

import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux';
import type { RootState, AppDispatch } from './Store';

// Use throughout your app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;

最后这里是 app.tsx-

function MyApp(props: MyAppProps) {
  const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
  return (
    <CacheProvider value={emotionCache}>
      <Head>
        <meta name="viewport" content="initial-scale=1, width=device-width" />
      </Head>
      <ThemeProvider theme={theme}>
        <CssBaseline />
        <NextProgress
          delay={2000}
          options={{ showSpinner: false }}
          color="#eb5525"
        />
        <Component {...pageProps} />
      </ThemeProvider>
    </CacheProvider>
  );
}
export default wrapper.withRedux(MyApp);

*** 使用相同的代码我没有收到任何警告。但是当我将项目更新到最新包时,我收到错误。

请帮助我实际上在哪里我必须根据警告更新我的代码?


警告来自this https://github.com/kirill-konshin/next-redux-wrapper/blob/master/packages/wrapper/src/index.tsx#L229线。所以每当有人使用时就会出现警告包装器.withRedux方法(旧方法)。

为了解决这个问题,我们必须使用使用WrappedStore创建一个store,并使用react-redux的Provider将商店传递给孩子们:

import { FC } from "react";
import { Provider } from "react-redux";
import type { AppProps } from "next/app";
import { wrapper } from "../app/store";

const MyApp: FC<AppProps> = ({ Component, ...rest }) => {
  const { store, props } = wrapper.useWrappedStore(rest);
  const { emotionCache = clientSideEmotionCache, pageProps } = props;
  return (
    <Provider store={store}>
      <CacheProvider value={emotionCache}>
        ...
        <Component {...pageProps} />
        ...
      </CacheProvider>
    </Provider>
  );
};

export default MyApp;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

您正在使用遗留实现。请更新您的代码:使用createWrapper() 和wrapper.useWrappedStore()。 nextjs 还原? 的相关文章

随机推荐

  • tensorflow:reshape()可以创建副本吗?

    在他们的 API v4 中 torch 引入了reshape 更加符合 numpy 的风格 以前 改变火炬张量的形状是通过view 我想知道是否view 现在将被弃用并查看docs https pytorch org docs stable
  • 如何更新 Google Drive v3 PHP 中的文件

    我似乎无法使用以下代码更新谷歌驱动器中的文件 一切正常 但文件保持不变 我正在使用 v3 api function updateFile service fileId data try emptyFile new Google Servic
  • 将类应用于 br 标签? [复制]

    这个问题在这里已经有答案了 以下是有效的 HTML 吗 br class something 作为一个 HTML 元素 我不明白为什么它不会 但我认为我从未见过它被使用 Yes See 规格 https www w3 org TR html
  • tkinter 中的按钮命令选项

    在下面的小 GUI 应用程序中 当我使用按钮的命令选项来调用函数时 它不是这样工作的 self update 相反 它的工作原理如下 self update 为什么这样 按钮的命令选项是否有某种特殊的工作方式 我认为应该用这些大括号调用方法
  • 一些 Express.Router() 路由不执行中间件函数

    我正在尝试解决 Express router 的实现问题 而不是触发分配给它的中间件函数 我编写了一个相当大的应用程序 并尝试向我的路径添加更多端点 但由于某种原因 第 9 条路线被加载但没有触发该功能 app js server use
  • 将图像放置在居中的 div 后面

    我的网站有 900px div content以margin left auto and margin right auto 我有一个图像需要在 div 后面显示 该图像将部分重叠 content 图像目前设置为显示为块 我可以将其到达需要
  • Bootstrap 轮播可以仅旋转部分幻灯片吗?

    我有一个直接来自引导站点的香草轮播 carousel carousel interval 2000 它有 5 张幻灯片和 5 个指标 1 2 3 A B 我希望轮播能够自动循环播放幻灯片 1 2 和 3 然后重复 但是 如果我单击幻灯片 A
  • 无法让 JQuery 在母版页中工作

    我有一个没有母版页的表单中的示例 jquery 它工作正常 我试图在我的母版页中使用相同的功能 但它不起作用 我正在使用 ASP NET 这是我的代码 WebForm 这有效
  • 为什么要让用户在 PayuMoney 网关的 android SDK 中登录?

    我正在尝试集成适用于 Android 的 PayUMoney SDK 并成功将 SDK 添加到我的应用程序中 当用户单击支付按钮时 将打开登录页面 为什么要让用户登录 创建 payu 帐户 一旦用户按下支付按钮 支付选项就会打开 但事实并非
  • NSPredicate 中 ALL 、 ANY 和 SOME 运算符之间的区别

    我真的很难理解这 3 个 看起来像ANY and SOME做同样的事情 但我看不出有什么区别ALL 让我们有一个组列表 每个团体都有人类型的成员 每个人都有一个年龄 所有会员年龄 gt 30 意味着您将找到一个成员全部年龄超过 30 岁的群
  • Django unique_together 与可为空的外键

    我在使用 Sqlite 的开发机器中使用 Django 1 8 4 并且有以下模型 class ModelA Model field a CharField verbose name a max length 20 field b Char
  • 搜索自然语言句子结构

    存储和搜索自然语言句子结构树数据库的最佳方式是什么 Using OpenNLP 的 http incubator apache org opennlp 英语树库解析器 我可以对任意句子进行相当可靠的句子结构解析 我想做的是创建一个工具 可以
  • UserProfile 状态在 bot v4 中的用户之间保持不变

    当我有两个机器人实例时 如果我将机器人部署到 Azure 则可以是两个模拟器窗口或两个浏览器 输入的第一个名称对于所有其他实例都是持久的 实例一 https i stack imgur com WsPw7 jpg https i stack
  • 将spawn()的stdout/stderr重定向到Ruby中的字符串

    我想使用spawn 对于多个并发子进程 在Ruby 中执行外部进程 并将stdout 或stderr 收集到一个字符串中 这与使用Python 的子进程Popen communicate 可以完成的方式类似 我尝试将 out err 重定向
  • ReadableByteChannelImpl 如何处理中断

    我正在尝试使用Channels newChannel包装输入流以支持中断 我看到了关于这是否有效的相互矛盾的信息 包括 ReadableByteChannelImpl 中的注释 Not really interruptible In Rea
  • 带有字符串键的 Lua 表不能使用数字索引?

    我是 Lua 的初学者 我认为使用字符串键将值推送到表中也会自动执行数字索引 但我认为我错了 我的代码 local t t name John t age 30 print Name t name nAge t age 虽然这段代码运行良好
  • 使用 css 3d 转换后如何修复 Safari 5 Mac OS X 中的脆文本?

    当应用 css 3d 变换的元素之后 相对和绝对定位的元素触发奇怪的行为时 我遇到了问题 为了解决这个问题 我必须设置背景颜色 但是如果我需要透明度怎么办 这是重现该错误的最低限度 http jsfiddle net 8VABq 3 htt
  • 如何获取 DD-MM-YYYY 格式的日期

    我正在使用 Parse 数据库 我存储日期格式 使用控制台时我得到这种格式 Tue Jul 18 2017 15 46 47 GMT 0100 CET 我想获得这种格式 18 07 2017 有什么想法请 可以使用以下代码来完成 let t
  • 抓取屏幕分辨率并根据大小显示结果

    我正在尝试根据屏幕分辨率大小显示数据库的结果 我上周发布了一个关于如何获取宽度的问题 并且能够在此处的一些想法的帮助下提出这个jquery 但无法完成第二个方面 即根据大小显示结果
  • 您正在使用遗留实现。请更新您的代码:使用createWrapper() 和wrapper.useWrappedStore()。 nextjs 还原?

    我在使用 redux 工具包和 next js 时遇到错误 我面临着这个遗留警告 You are using legacy implementaion Please update your code use createWrapper an