I have set up my store correctly and everything works perfectly fine on ios. But on android with the exact same code, the dispatch action has no effect, it does not populate my context with the value returned from my APi.
Since it is exactly the same code, I have been struggling to figure out what the issue could be.
I am using
"react-redux": "^7.2.1",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"react-native": "0.66.4",
calling the action on app launch
const dispatch = useDispatch()
const trans = useSelector(state => state.translation);
useEffect(() => {
fetchTranslations(dispatch)
}, [])
reducer
import React from "react";
const initState = {};
const TranslationReducer = (state = initState, action) => {
switch (action.type) {
case 'FETCH_TRANSLATIONS':
return action.payload.data
default:
return state;
}
};
export default TranslationReducer
action
import { get } from '../api/query';
export function fetchTranslations(dispatch) {
try {
return (
get('/api/v3/labels/mobile_app/')
.then(res => {
console.log('res', res)
return res.json()
})
.then(response => {
console.log('response', response)
dispatch({
type: 'FETCH_TRANSLATIONS',
payload: response
})
})
)
} catch (e) {
console.log('error', e)
}
}
everything is correctly returned from the api, but dispatching the action does nothing to the state, it stays empty on android, but works fine on ios.