Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs “如何修复错误”;道具'className'不匹配。服务器:";MuiFormLabel-root-75..“;?_Reactjs_Material Ui_Next.js - Fatal编程技术网

Reactjs “如何修复错误”;道具'className'不匹配。服务器:";MuiFormLabel-root-75..“;?

Reactjs “如何修复错误”;道具'className'不匹配。服务器:";MuiFormLabel-root-75..“;?,reactjs,material-ui,next.js,Reactjs,Material Ui,Next.js,我使用了NextJS,并尝试使用它来使用“@materialui/core”。当我尝试使用用户textfield时,我遇到了错误: index.js:2178警告:PropclassName不匹配。服务器: “MuiFormLabel-root-75 MuiInputLabel-root-64 MUIIInputLabel-formControl-69 MUIIInputLabel-animated-72“客户端: “MuiFormLabel-root-16 MuiInputLabel-root

我使用了
NextJS
,并尝试使用它来使用“@materialui/core”。当我尝试使用用户
textfield
时,我遇到了错误:

index.js:2178警告:Prop
className
不匹配。服务器: “MuiFormLabel-root-75 MuiInputLabel-root-64 MUIIInputLabel-formControl-69 MUIIInputLabel-animated-72“客户端: “MuiFormLabel-root-16 MuiInputLabel-root-5 MUIIInputLabel-formControl-10 MUIIInputLabel-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>
    )
  }
}

我没有在代码库的其他文件中导入@material ui的任何部分。只有代码示例。

我有这个问题,非常令人沮丧。。。但最后我解决了

在我的解决方案中,我安装了reactjs、next和material ui。。。问题与服务器和客户端如何加载文件和样式有关

但重要的是要做到这一点:

您正在使用CLASE,但我建议更改为使用如下挂钩:

import React, {useState} from 'react'
import Button from '@material-ui/core/Button'
import TextField from '@material-ui/core/TextField'

const Footer = (props) => {
    const formTypes = ['employer', 'employee'];
    const formRef = null;

    const [formType, setFormType] = Footer.formTypes[0];

    const myForm = (
        <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>
    );

    return (
        {myForm}
    )
}

export default Footer;
import React,{useState}来自“React”
从“@material ui/core/Button”导入按钮
从“@material ui/core/TextField”导入TextField
常量页脚=(道具)=>{
const formTypes=[“雇主”、“雇员”];
const formRef=null;
const[formType,setFormType]=Footer.formTypes[0];
常量myForm=(
发送
);
返回(
{myForm}
)
}
导出默认页脚;
但是实现您的代码将如下所示

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 () {
    const myFormWithClasses = (
             <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>
    )
    return (
     {myFormWithClasses}
    )
 }
}
从“React”导入React
从“@material ui/core/Button”导入按钮
从“@material ui/core/TextField”导入TextField
导出默认类页脚扩展React.Component{
静态formTypes=['employer','employee']
formRef=null
状态={
formType:Footer.formTypes[0]
}
渲染(){
常量MyFormWithClass=(
发送
)
返回(
{MyFormWithClass}
)
}
}

关键是将组件的元素隔离在一个变量中,该变量在被呈现之前已被声明。请查看以下示例:?我认为诀窍在于使用MaterialUI的“createGenerateClassName”方法使客户端和服务器具有相同的类名。
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 () {
    const myFormWithClasses = (
             <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>
    )
    return (
     {myFormWithClasses}
    )
 }
}