我陷入了困境。我在管理面板上使用react-admin。
现在,在编辑联系人时,将使用资源类型GET_ONE
调用API。
我想将数据添加到减速器中,以便我的组件可以使用该数据。当前,正在调用API,并且字段在获取值。
我只想将数据添加到reducer或要调用组件componentDidMount
方法上的API。
有人可以帮我吗?
答案 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)
};
};