Reputation: 632
const response = yield call(fetch, `${config.backendUrl}/verify`, {
method: 'POST'
})
const responseJson = yield call(response.json)
console.log(responseJson)
This is code from redux-saga. Yield hangs and console.log
does not print anything. But if I replace response.json
with () => response.json()
it works. Why?
Upvotes: 1
Views: 219
Reputation: 37938
That's because when you invoke yield call(response.json)
the response.json
is called with wrong context (this
).
You could fix this with bind
(e.g. yield call(response.json.bind(response))
), or by specifying context
(e.g. yield call([response, response.json])
), but call
here is really useless. You can just:
const responseJson = yield response.json();
Upvotes: 1