Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.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
Forms 反应+;Redux Noob-提交表单数据_Forms_Reactjs_Redux - Fatal编程技术网

Forms 反应+;Redux Noob-提交表单数据

Forms 反应+;Redux Noob-提交表单数据,forms,reactjs,redux,Forms,Reactjs,Redux,在关于Redux和react的一些教程之后,我刚刚开始尝试react,控制台中出现了一个错误: 警告:无法为无状态函数组件提供ref(请参阅ref 通过登录创建的字段组中的“用户名”)。试图访问此文件 ref将失败 将表单字段输入值传递到“我的提交”按钮的正确方式是什么?这些值是否应该进入redux存储?看完文档后:在这种情况下,我似乎应该避免引用参考文献。那么,如果没有refs,如何获取提交按钮的输入值?谢谢你的帮助 Login.jsx react(无状态)中的功能组件没有引用 从官方 参考文

在关于Redux和react的一些教程之后,我刚刚开始尝试react,控制台中出现了一个错误:

警告:无法为无状态函数组件提供ref(请参阅ref 通过登录创建的字段组中的“用户名”)。试图访问此文件 ref将失败

将表单字段输入值传递到“我的提交”按钮的正确方式是什么?这些值是否应该进入redux存储?看完文档后:在这种情况下,我似乎应该避免引用参考文献。那么,如果没有refs,如何获取提交按钮的输入值?谢谢你的帮助

Login.jsx


react(无状态)中的功能组件没有引用

从官方

参考文献和功能组件 您不能对功能组件使用ref属性,因为它们没有实例:

如果需要引用,请使用ES6类,如果不需要,请使用父级
Login
组件中的
this.state
和类语法,并在
this.setState(yourState)
字段组上的输入值更改时使用该类

然后在你的生活中你会做什么

handleClick(event) {
    const username = this.state.username
    const password = this.state.password
    const creds = { username: username.value.trim(), password: password.value.trim() }
    this.props.onLoginClick(creds)
  }
从:

但是,只要引用DOM元素或类组件,就可以在功能组件内使用ref属性:

handleClick(event) {
    const username = this.state.username
    const password = this.state.password
    const creds = { username: username.value.trim(), password: password.value.trim() }
    this.props.onLoginClick(creds)
  }