【问题标题】:How to put change in store redux-form如何在商店 redux-form 中进行更改
【发布时间】:2019-11-15 09:31:28
【问题描述】:

我正在使用 react-autosuggest 进行自动完成输入(获取类型)。我的代码基于来自 react-admin 的 AutoCompleteArrayInput 和 material-ui 中的 react-autosuggest。我用 addField 装饰我的组件,以便使用 redux-form。

但是当我将我的组件放在SimpleForm 中时,提取和选择工作正常,所有输入在redux 存储中都有一个值,但不是我的。当我查看反应开发工具时,我的组件周围有一个 Field 组件

我尝试通过 redux-form 中的 change 手动执行此操作,但它不起作用。 如何在 redux 商店中连接我的组件以提交我的所有输入?

export default connect(
  null,
  {
    getSearched: crudGetAll,
  },
)(
  compose(
    addField,
    translate,
  )(ButtonSearchWithAutocompletion),
);
onSuggestionSelected = (event, { suggestion }) => {
    const { onSelectedValue, source } = this.props;

    change(REDUX_FORM_NAME, source, suggestion.id);
    onSelectedValue(suggestion);
  };

【问题讨论】:

    标签: field redux-form react-admin


    【解决方案1】:

    我团队中的某个人帮助我解决了这个问题,对于面临同样问题的任何人,解决方案是,将 redux-formchange 放在我的 index.js 中,如下所示:

    import { change } from 'redux-form';
    import { connect } from 'react-redux';
    import compose from 'recompose/compose';
    
    import ButtonSearchWithAutocompletion from './component';
    
    export default connect(
      null,
      {
        getSearched: crudGetAll,
        change,
      },
    )(
      compose(
        addField,
        translate,
      )(ButtonSearchWithAutocompletion),
    );
    

    在我的 component.js 中,我使用 change 作为道具:

    onSuggestionSelected = (event, { suggestion }) => {
        const { onSelectedValue, source, change } = this.props;
    
        change(REDUX_FORM_NAME, source, suggestion.id);
        onSelectedValue(suggestion);
      };
    

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 2016-09-30
      • 2017-02-26
      • 1970-01-01
      • 2022-11-04
      • 2018-06-18
      • 2020-08-11
      • 2018-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多