Next.Js 13:Redux提供程序显示存储以外的内容

vnzz0bqm  于 2023-03-18  发布在  其他
关注(0)|答案(1)|浏览(125)

所以我在试用Next.Js 13时,发现redux提供程序有一些奇怪的行为。我看到的不是状态切片,而是一些名为tree、cache、prefetchCache、pushRef、focusAndScrollRef和canonicalUrl的对象。不管怎样,我对Next.JS还是个新手。下面是我的设置:

// client/app/layout.tsx

import React from "react";
import Providers from "./providers";

'use client' // <-- tried with both use client and without

export default function RootLayout({ children }) {
    return (
      <html lang="en">
        <head />
            <body>
        <Providers>
                {children}
        </Providers>
            </body>
      </html>
    );
  }
// client/app/providers.tsx

'use client'

import React from 'react'
import { Provider } from 'react-redux'
import {store} from '../src/redux/store'

const Providers = ({children}:React.PropsWithChildren) => {
    return (
        <Provider store={store}>
            {children}
        </Provider>
    )
}

export default Providers
wqlqzqxt

wqlqzqxt1#

我遇到了同样的问题,这是一个nextJs bug。您可以在这里找到更多信息:https://github.com/reduxjs/redux-toolkit/issues/3154
在redux工具的标签页中,你会看到“next/router”,在这里你会找到所有的对象,比如树、缓存......如果你选择下一个标签页,你会找到当前的nextjs商店。
确保按如下方式创建存储:

export function makeStore() {
  return configureStore({
    reducer: combineReducers({
      search: searchReducer,
      language: languageReducer
    }),
    devTools: true
  });
}

export const store = makeStore();

相关问题