I'm having this issue when I'm trying to invoke a callback after the promise resolves (using .then) It turns out that this gives my const request some kind of different promise that reducer returns as undefined:
action:
export function lookup(company, callback) {
const id = company.textfield;
const url = `${ROOT_URL}${id}`;
const request = axios.get(url)
.then(() => callback())
return {
type: LOOK_UP,
payload: request,
meta: id
};
}
reducer:
import { LOOK_UP } from '../actions/index';
export default function(state = {}, action) {
switch (action.type) {
case LOOK_UP:
const data = action.payload.data;
const id = action.meta;
if (data.Success === true) {
return { ...state, [id]: data.CompanyInformation };
} else {
return state;
}
}
return state;
}
As you can see I pass the data from API that axios get to my reducer. After this I set the state and I need to invoke that callback that is in 'actions' (it creates then another action call inside component). Unfortunatelly, I got error that in reducer const data = action.payload.data is undefined.
When I don't use this callback everything works fine, but the case is that I neet to invoke that callback only after this reducer returns new state.
request = axios.get(url)
? If it's only that the callback need the response as an argument, then you can simply use my first suggestion but withcallback(dataFromRequest);
Orcallback(dataFromRequest.data);
or what ever info you are interested in. You can also include the if-statement. etc. and doPromise.reject( )
ifdataFromRequest.data.SUCESS !== true
. – jonaheredux-promise
. Is is this one? github.com/acdlite/redux-promise The examples are so few there that it's hard to see how it's supposed to be used. Is itredux-promise
that adds the.Success
? – jonahe