0

在使用 next 时,我尽量配置 store,特别是 next-redux-wrapper。

我根据文档做了所有事情并且能够做到。没有错误,但控制台出现一条奇怪的消息

4. WrappedApp created new store with withRedux(MyApp) {initialState: undefined, initialStateFromGSPorGSSR: undefined}

我可以肯定状态存在,这是真的!

import { HYDRATE } from "next-redux-wrapper";
import { combineReducers } from "redux";
import { topNavReducer } from "./topNavReducer"; 

const rootReducer = combineReducers({ 
  topNavigation: topNavReducer
}) 

export const reducer = (state, action) => { 
  if (action.type === HYDRATE) {
    const nextState = {
      ...state, // use previous state
      ...action.payload, // apply delta from hydration
    }
    if (state.count) nextState.count = state.count // preserve count value on client side navigation 
    return nextState
  } else {  
    console.log(rootReducer(state, action)); //true
    return rootReducer(state, action)
  }
} 

//MYAPP
 
import '../styles/globals.css' 
import React from 'react';
import { wrapper } from 'store';

const MyApp = ({ Component, pageProps }) => {
  return <Component {...pageProps} />
} 

export default wrapper.withRedux(MyApp);

回答

wait  - compiling...
event - compiled successfully
{
  topNavigation: [
    { title: 'Сравнение', href: '/compare', counter: 0 },
    { title: 'Закладки', href: '/wishlist', counter: 0 }
  ]
}
4. WrappedApp created new store with withRedux(MyApp) { initialState: undefined, initialStateFromGSPorGSSR: undefined }

我不明白我该如何解决这个问题。

4

0 回答 0