自定义预定义的请求类型

时间:2019-07-29 08:23:06

标签: javascript reactjs react-admin

我陷入了困境。我在管理面板上使用react-admin。 现在,在编辑联系人时,将使用资源类型GET_ONE调用API。

我想将数据添加到减速器中,以便我的组件可以使用该数据。当前,正在调用API,并且字段在获取值。

我只想将数据添加到reducer或要调用组件componentDidMount方法上的API。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

您可以像这样在组件中使用调度方法...

组件

/** Import */
import { bindActionCreators } from "redux";

/** methods */
selectProduct = index => {
   this.props.dispatch({ type: "selectedProduct", payload: index });
};

onDeleteProduct = index => {
   this.props.onDeleteProduct(index);
};

/** actions */
const mapActionsToProps = dispatch => {
  return {
    dispatch,
    ...bindActionCreators({ onDeleteProduct: deleteProduct }, dispatch)
  };
};