【发布时间】:2020-09-27 15:16:14
【问题描述】:
我有一个问题并且已经搜索了很多,但论坛上没有一个解决方案对我有用。 我在屏幕上调用了 6 个 API(没有加载程序),底部有一个按钮可以将用户导航到另一个屏幕。
我在 componentDidMount() 中添加了编码,
componentDidMount() {
this.props.API1();
this.props.API2();
this.props.API3();
}
但是,直到 i 所有三个 API 的响应都出现在 getderivedatatefromprops 中,用于导航到另一个屏幕的底部按钮不起作用。
this.props.API1() 是定义如下的 redux 动作
export const API1 = () => {
return (dispatch) => {
new Promise(async () => {
const body = {
method: 'GET',
url: "get url of API",
};
axios(body)
.then((response) => {
dispatch({
type: 'GETRESPONSE',
payload: { response: response.data, error: false },
});
})
.catch((error) => {
dispatch({
type: 'GETRESPONSE',
payload: { response: error?.response, error: true },
});
});
});
};
};
【问题讨论】:
-
听起来你在主线程上调用同步调用。 API1、2、3 是什么样的?
-
这是 redux 操作。我已经修改了上面的代码以显示 redux 中如何提及操作
标签: reactjs react-native axios