Mock api in react redux-thunk project returning undefined
I may well have this wrong, but it seems like you are replacing
export const get = (url, params, responseType = 'json') => cancellable({
with export const get = item => new Promise((resolve) => {
which has a different API.
Regardless, have you tried logging the value of item
in the mock get function. I'm guessing it isn't "employee" which is the only property in data
.
Yes, that was my goal, to replace the call that was pointing to the backend API, with the call where I would return the mock data. I have tried to log the value of the item, but I get undefined
ok, so there's an awful lot of abstraction going on there. Id suggest starting by replacing get
in data/rest/restMethods.jsx
directly with a version that returns a promise, get it working, and then break it out. That way you're not dealing with too many unknowns at once.
I had done similar using redux-saga. After debugging, I had found that there must be data
property as root key. Here's how you should do:
const employee = { data: { // root key of employee items: [ { name: 'Bhojendra' }, { name: 'Rauniyar' } ] }}// and no need to use setTimeout, we're just resolving some constant dataexport const getItems = item => new Promise(resolve => resolve(employee))
Now, I hope you know why data is undefined
with your code.
Still not clear?
Response looks for the data
property. That's it.