在onchange选择时,在redux-form上调度自定义操作

Vic*_*yos 6 redux-form react-redux

给定一个自定义组件:

export const RenderDropDown = (props) => {
    const {values, input, label, type, meta: {touched, error, active}} = props;

    var options = function (value, index) {
        return <Option key={index}
                       value={value} />
    };

    return(
        <div>
        <select {...input}>
            <option value="">--- Select a nationality ---</option>
            {values.map(options)}
        </select>
        </div>
    )
}
Run Code Online (Sandbox Code Playgroud)

包含在Redux-form Field组件中

<Field name="nationality" component={RenderDropDown} values={props.nationalities}/>
Run Code Online (Sandbox Code Playgroud)

我希望在select触发"onChange"事件时,除了Redux-form操作之外还会调度自定义操作(AKA @@ redux-form/change)

我怎么能做到这一点?

我尝试通过props调用函数来调用并在<select>标记上设置onChange处理程序,但这会覆盖redux-form onChange.

任何帮助赞赏!

ino*_*tia 9

您需要onChange在自己的自定义中手动调用redux-form onChange以更新redux-form值.像这样:

const { onChange, ... } = props;
...
<select onChange={(e) => {
    const val = e.target.value
    // whatever stuff you want to do
    onChange(val)
}} />
Run Code Online (Sandbox Code Playgroud)