调用actionCreator函数无法通过bindActionCreators工作

时间:2018-05-18 10:10:05

标签: reactjs redux redux-thunk

我正在使用actionCreator附加调度,如bellow

public class EditableTextCell<E> extends TableCell<E, String> {

    private final TextField textField;
    private boolean updating = false;

    public EditableTextCell() {
        textField = new TextField();
        textField.textProperty().addListener((o, oldValue, newValue) -> {
            if (!updating) {
                ((WritableValue<String>) getTableColumn().getCellObservableValue((E) getTableRow().getItem())).setValue(newValue);
            }
        });
    }

    @Override
    protected void updateItem(String item, boolean empty) {
        super.updateItem(item, empty);
        if (empty) {
            setGraphic(null);
        } else {
            setGraphic(textField);
            if (!Objects.equals(textField.getText(), item)) { // prevent own updates from moving the cursor
                updating = true;
                textField.setText(item);
                updating = false;
            }
        }
    }
}

并像这样调用actionCreator函数

function mapDispatchToProps(dispatch) {

  return {
    actions: bindActionCreators(Object.assign({},basicActions), dispatch)
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(NewClientSetup);

这是basicActions.js

componentCallback:text => actions(basicActions.selectOption(text))

但它的给出错误'Uncaught TypeError:actions不是函数'

这是有效的

export function selectOption(text){
    debugger;
    const actionObj = {
        type: types.SELECT_OPTION,
        id: nextActionId++,
        text
    };
    return actionObj;
}


export function requestSuccess(){
    console.log('inside requestSuccess');
    return {type:'SUCCESS',id:1}
}

export function fetchS1Users(parentUserId){
debugger;
    axios.get(url, {
        params: {
          parentUserVal: parentUserId
        },
        responseType: 'json'
      })
      .then(function (response) {
        console.log('res '+response.data);
        console.log('res JSON '+JSON.stringify(response.data));
      })
      .catch(function (error) {
        console.log(error);
      });

    return {
        id: nextActionId++,
        type: types.FETCH_USERS,
        inputParam: parentUserId,
        s1users:{}
    }
}

1 个答案:

答案 0 :(得分:0)

使用bindActionCreators绑定动作后,您可以在道具中使用它们,而不是像

那样调用动作

this.props.actions.selectOption()