ReactJS:如何在不使用redux表单的情况下将表单值作为JSON对象提交。

ReactJS:如何在不使用redux表单的情况下将表单值作为JSON对象提交。,reactjs,redux,react-redux,redux-form,Reactjs,Redux,React Redux,Redux Form,我正在使用redux form将表单值作为JSON对象提交给POST服务。但是redux表单字段()不支持像onChange,onBlur这样的事件。所以我想使用默认组件,比如,,但是如果我使用普通html组件,像onChange这样的事件就会起作用。但是在这里,如果没有redux表单,我就无法将表单值作为对象提交给服务。请引导 谢谢, Shashredux表单通过传递给的自定义组件支持它 其中一种方法是(摘自文档) 组件 这可以是您编写或导入的任何组件类 来自第三方库 //MyCustomIn

我正在使用
redux form
将表单值作为JSON对象提交给POST服务。但是
redux表单
字段(
)不支持像
onChange
onBlur
这样的事件。所以我想使用默认组件,比如
,但是如果我使用普通html组件,像onChange这样的事件就会起作用。但是在这里,如果没有
redux表单
,我就无法将表单值作为对象提交给服务。请引导

谢谢,
Shash

redux表单通过传递给
的自定义组件支持它

其中一种方法是(摘自文档)

  • 组件
  • 这可以是您编写或导入的任何组件类 来自第三方库

    //MyCustomInput.js

    import React, { Component } from 'react'
    
    class MyCustomInput extends Component {
      render() {
        const { value, onChange } = this.props
        return (
          <div>
            <span>The current value is {value}.</span>
            <button type="button" onClick={() => onChange(value + 1)}>Inc</button>
            <button type="button" onClick={() => onChange(value - 1)}>Dec</button>
          </div>
        )
      }
    }
    Then, somewhere in your form...    
    import MyCustomInput from './MyCustomInput'
    
    <Field component={MyCustomInput}/>
    
    import React,{Component}来自“React”
    类MyCustomInput扩展组件{
    render(){
    const{value,onChange}=this.props
    返回(
    当前值为{value}。
    onChange(值+1)}>Inc
    onChange(值-1)}>Dec
    )
    }
    }
    然后,在你身体的某个地方。。。
    从“./MyCustomInput”导入MyCustomInput
    
    因为您已经在使用redux表单提交您的值,所以让redux表单提交您的值会容易得多


    它甚至不必是自定义组件,您仍然可以使用onChange,只需简单的“选择”作为组件。您所指的文档是针对6.0.0 alpha 4的,这里是最新的版本:您可以看到您也可以将onChange prop传递给字段。但是是否可以像这样传递onChange
    此处
    handleChange
    函数包含一些递增和递减功能。我不确定这是否有效,因为redux表单为字段渲染函数提供了一个
    onChange
    道具。您始终可以使用不同的道具名称(如
    customOnChange
    )来提供处理程序函数。然后调用
    onChange
    (由redux表单提供,并且是传播事件所需的)和
    customOnChange
    (执行自定义逻辑)。但是,我想知道将表单值作为JSON提交到
    onChange
    之间有什么联系。表单值已作为Javascript对象提供给提交处理程序。