I have an issue very similar to this question. (See below)
My question is, what versions of React and Material UI should be installed and how?
我有一个与这个问题非常相似的问题。(见下文)我的问题是,应该安装哪些版本的Reaction和Material UI,以及如何安装?
import * as React from 'react';
import {Button} from '@mui/material';
function App() {
return (
<div>
<Button>hello</Button>
</div>
);
}
Material UI Button uses useContext hook but is not using it appropriately.
材料用户界面按钮使用了useContext挂钩,但使用不当。
ERROR
Cannot read properties of null (reading 'useContext')
TypeError: Cannot read properties of null (reading 'useContext')
at Object.useContext (http://localhost:3000/main.1060eb1d58db4786d492.hot-update.js:12575:25)
at Button (http://localhost:3000/main.1060eb1d58db4786d492.hot-update.js:2470:59)
at renderWithHooks (http://localhost:3000/static/js/bundle.js:21336:22)
at updateForwardRef (http://localhost:3000/static/js/bundle.js:23907:24)
at beginWork (http://localhost:3000/static/js/bundle.js:25954:20)
at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:10928:18)
at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:10972:20)
at invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:11029:35)
at beginWork$1 (http://localhost:3000/static/js/bundle.js:30903:11)
at performUnitOfWork (http://localhost:3000/static/js/bundle.js:30150:16)
Note: I installed/used create-react-app
as my method of getting react. However, I've read that this is no longer maintained.
注意:我安装/使用了Create-Reaction-app作为获取Reaction的方法。然而,我读到这一点不再得到维护。
Edit: Package.json listed
编辑:列出Package.json
{
"name": "my-material-ui-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@mui/icons-material": "^5.14.8",
"@mui/material": "^5.14.8",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.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"
]
}
}
更多回答
Can you add package.json
contents to your question?
您能在您的问题中添加Package.json内容吗?
@RobinThomas, done!
@罗宾·托马斯,完成!
I think packages @emotion/react
and @emotion/styled
are missing, did you try installing them?
我想包@emotion/react和@emotion/styled丢失了,你试过安装它们吗?
我是一名优秀的程序员,十分优秀!