ASP.NET Core带有Redux的React模板分发问题

时间:2018-10-25 08:59:48

标签: asp.net reactjs react-redux

我正在处理这个项目,我们正在使用MS的模板,并且一切正常,但是对于此特定任务,我需要redux的“默认”调度方法,因此我可以专注于一些表单输入和我不知道如何获得它。

import { ApplicationState } from '../../../store/index';
import { connect } from 'react-redux';
import * as GlobalState from '../../../store/Global';
import { Field } from 'redux-form';
import SelectHour from '../Selects/SelectHour';
import Select from '../Selects/Select';
import MultiSelectComponent from '../Selects/MultiSelectComponent';
import Days from '../Days';
import { getFormInitialValues } from 'redux-form';
import { Field, focus, blur } from 'redux-form';
import SelectHour from './SelectHour';

class WorkingDays extends React.Component<Props, State> {
...
}

export default connect(
     (state: ApplicationState) => state.global,
     GlobalState.actionCreators
)(WorkingDays) as typeof WorkingDays;

我如何获得派遣服务,以便可以像这样使用它?

this.props.dispatch.focus(something, something)

1 个答案:

答案 0 :(得分:0)

dispatch是一个函数,因此您无法使this.props.dispatch.focus(something, something)正常工作。 但是可以这样获得this.props.focus(something, something)

export default connect(
     (state: ApplicationState) => state.global,
     (dispath) => ({
         focus: (value1, value2) => {
             const action = yourAction(value1, value2)
             dispath(action)
         }
     })
)(WorkingDays) as typeof WorkingDays;

我从未使用过MS react-redux模板,所以不知道您的GlobalState是什么样子!