Next.js v12.0
next-redux-包装器。
每当我使用适当的 next/link 元素导航离开页面,然后再次返回(使用另一个链接 el)时,状态将重置为初始值,因此执行另一个获取。奇怪的是,我以相同的方式设置了另一个“事务”切片,只不过它包含一组事务对象,并且其中一个工作得很好(导航离开并返回,并且数据在持续存在时不会重新获取)在商店中)代码如下,如有任何建议,我们将不胜感激。
商店.js
import { HYDRATE, createWrapper } from "next-redux-wrapper";
import thunkMiddleware from "redux-thunk";
import address from "./address/reducer";
import transactions from "./transaction/reducer";
const bindMiddleware = (middleware) => {
if (process.env.NODE_ENV !== "production") {
const { composeWithDevTools } = require("redux-devtools-extension");
return composeWithDevTools(applyMiddleware(...middleware));
}
return applyMiddleware(...middleware);
};
const combinedReducer = combineReducers({
transactions,
address,
});
const rootReducer = (state, action) => {
if (action.type === HYDRATE) {
const nextState = {
...state, // use previous state
...action.payload, // …Run Code Online (Sandbox Code Playgroud)