Redux/store.js
import { configureStore, combineReducers } from '@reduxjs/toolkit';
import userReducer from './slices/userSlice'
import { persistReducer, persistStore } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
const rootReducer = combineReducers({
user: userReducer,
});
const persistConfig = {
key: 'root',
storage,
version: 1,
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
export const store = configureStore({
reducer: persistedReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({ serializableCheck: false }),
});
export const persistor = persistStore(store);
Main.jsx
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'
import { store, persistor } from './Redux/store.js'
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react'
ReactDOM.createRoot(document.getElementById('root')).render(
<PersistGate persistor={persistor}>
<Provider store={store}>
<App />
</Provider>
</PersistGate>,
)
Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
Uncaught TypeError: Cannot read properties of null (reading 'useMemo')
我曾多次try 将Reduxstore 添加到应用程序中,完全遵循格式,并参考了其他项目.我不知道为什么错误出乎意料地发生,即使我真的遵循了Redux存储的正确格式.
我完全遵循了文档,错误意外发生.