Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read properties of null (reading 'useMemo')

Am getting "TypeError: Cannot read properties of null (reading 'useMemo') error Redux in my react redux application. I made a very simple react redux application. but am keep getting this error. searched about this error on Internet unfortunately didn't get any solution.

Redux folder structure:

src >> state(folder) >> store.js
reducer.js

reducer.js


const initialState={
    user:[]
}


export const userReducer=(state=initialState,action)=>{
    switch (action.type) {
        case "TEST_DATA":
                return state
        default:
            return state
    }
 
}

store.js

import {createStore,applyMiddleware} from "redux"
import {userReducer} from './reducer'
import {composeWithDevTools} from 'redux-devtools-extension'
import thunk from 'redux-thunk'


export const store=createStore(userReducer,composeWithDevTools(applyMiddleware(thunk)))

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { Provider } from 'react-redux';
import {store} from './state/store'


ReactDOM.render(
<Provider store={store}>
  <App />
</Provider>
  ,
  document.getElementById('root')
);

Tried to access state in App.jsx component

console.log(useSelector(state=>state))

am trying to fix it from last 3-4 days. Please help me am new to react and redux. Thanks in advance

like image 207
Keerthan Achar Avatar asked Dec 12 '25 15:12

Keerthan Achar


2 Answers

Following steps fixed the issue for me

  1. Check your react version in package.json
  2. If the react version is 18, then update "react-redux" package using npm i react-redux
  3. the "react-redux" package should have version 8 in package.json
  4. run npm start

Snippet from package.json file:

"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-redux": "^8.0.1",
like image 61
Harish Baskar Avatar answered Dec 15 '25 09:12

Harish Baskar


If anyone runs into this error with Next.js v13+ using the App directory (AKA App Router) then it could be because you're trying to use useMemo in a server component.

like image 40
nmajor Avatar answered Dec 15 '25 09:12

nmajor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!