【发布时间】:2018-12-05 19:21:27
【问题描述】:
我使用NextJS 并尝试使用“@material-ui/core”。当我尝试使用TextFiend 时,我得到了错误:
index.js:2178 警告:道具
className不匹配。服务器: "MuiFormLabel-root-75 MuiInputLabel-root-64 MuiInputLabel-formControl-69 MuiInputLabel-animated-72" 客户端: "MuiFormLabel-root-16 MuiInputLabel-root-5 MuiInputLabel-formControl-10 MuiInputLabel-animated-13"
我的代码:
import React from 'react'
import Button from '@material-ui/core/Button'
import TextField from '@material-ui/core/TextField'
export default class Footer extends React.Component {
static formTypes = ['employer', 'employee']
formRef = null
state = {
formType: Footer.formTypes[0]
}
render () {
return (
<footer className="footer">
<div className="footer__content">
<div className="footer__block">
<form id="footer__form">
<TextField type="text" name="name" label="Name"/>
<Button type="submit">Send</Button>
<input type="hidden" value={'employer'}/>
</form>
</div>
<div className="footer__block"></div>
</div>
</footer>
)
}
}
我该怎么做才能修复它?
我的 package.json:
{
"name": "custom-server-express",
"version": "1.0.0",
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
},
"dependencies": {
"@material-ui/core": "^3.6.1",
"@zeit/next-css": "^1.0.1",
"@zeit/next-sass": "^1.0.1",
"express": "^4.16.4",
"next": "^7.0.2",
"node-sass": "^4.10.0",
"normalize.css": "^8.0.1",
"react": "^16.6.3",
"react-dom": "^16.6.3"
},
"devDependencies": {
"babel-plugin-module-resolver": "^3.1.1"
}
}
我没有在我的代码库的其他文件中导入 @material-ui 的任何部分。只有代码示例。
【问题讨论】:
-
你看过这个样本了吗:github.com/mui-org/material-ui/tree/master/examples/nextjs?我认为诀窍是使用 material-ui 的“createGenerateClassName”方法为客户端和服务器提供相同的类名。
标签: reactjs material-ui next.js