Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read property 'getState' of null

TypeError: Cannot read property 'getState' of null. I did't install redux. I am trying to add the react antd Menu to my Sidebar page. but the problem is if I add inside my App.js it's not rendering. right now I am getting TypeError: Cannot read property 'getState' of null. can you tell me how to fix it?

showing this error: enter image description here

Index.js

import React from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import App from './App';

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

App.js

import React from 'react';
import Login from './Components/login';
import Sidebar from './Components/sidebar';
import Course from './Components/course';
import Downloads from './Components/downloads';
import Settings from './Components/settings';
import About from './Components/about';

function App() {
  return (
    <div className="container">
      <Sidebar />      
    </div>
  );
}

export default App;

Here is the code:

Sidebar.js

import React from 'react';
import { Menu } from 'antd';
import { MailOutlined, CalendarOutlined } from '@ant-design/icons';

function Sidebar() {
  return (
    <React.Fragment>
      <Menu.Item key="1" icon={<MailOutlined />}>
        Courses
      </Menu.Item>
      <Menu.Item key="2" icon={<CalendarOutlined />}>
        Downloads
      </Menu.Item>
    </React.Fragment>
  );
}

export default Sidebar;

package.json

{
  "name": "udeler",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "antd": "^4.9.1",
    "node-sass": "^4.14.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.1",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
like image 204
Gopalakrishnan T Avatar asked Sep 21 '25 09:09

Gopalakrishnan T


1 Answers

Menu.Item component is required to appear inside a Menu component.

So you need to wrap it in a Menu component.

The error you get is because internally the Menu creates a context and the Menu.Item tries to access it, but in your case does not find it.

like image 51
Gabriele Petrioli Avatar answered Sep 22 '25 22:09

Gabriele Petrioli