0
我正在使用帶有redux和Api調用的工作web版本,並將它們移植到React Native應用程序。不過,我注意到當試圖派遣一個thunk來進行API調用時,我似乎無法看到一個控制檯登錄到我的thunk中來確認派送。這讓我覺得有些東西沒有正確連接,但我不明白那是什麼。我錯過了什麼?react-redux不調度thunk api調用
我創建一個初始狀態的商店:當我登錄store.getState()
一切看起來不錯。
const initialState = {
config: fromJS({
apiUrl: "http://localhost:3000/account-data",
})
}
const store = createStore(
reducers,
initialState,
compose(
applyMiddleware(thunk),
)
)
我用mapDispatchToProps,我看到在我的道具
export function mapDispatchToProps(dispatch) {
return {
loadProducts:() => dispatch(loadProducts())
};
}
然而列表中的功能,當我檢查我的loadProducts
功能,我沒有看到一個控制檯日誌確認調度。這裏發生了什麼?爲什麼loadProducts不派發?在網絡版上,我可以確認網絡請求和日誌。在React Native上,我看不到網絡請求或這些控制檯日誌。
export function loadProductsCall() {
console.log('in RN loadProductsCall') //don't see this
const opts = constructAxpOpts();
return {
[CALL_API]: {
types: [
LOAD_REQUEST,
LOAD_SUCCESS,
LOAD_FAILURE
],
callAPI: (client, state) =>
client.get(`${state.config.get('apiUrl')}/members`, opts),
shouldForceFetch:() => false,
isLoaded: state => !!(state.core.resources.products.get('productsOrder') &&
state.core.resources.products.get('productsOrder').length),
getResourceFromState: (state) => state.core.resources.products.toJS(),
isLoading: state => !!state.core.resources.products.get('isLoading'),
getLoadingPromise: state => state.core.resources.products.get('loadingPromise'),
payload: {}
}
};
}
export function loadProducts() {
console.log('in loadProducts') //don't see this
return (dispatch) =>
console.log('in loadProducts dispatched 2') //don't see this either
dispatch(loadProductsCall())
.then((response) => {
return response;
});
}