Waiting for call to finish and then dispatch action in sagaPros/cons of using redux-saga with ES6 generators vs redux-thunk with ES2017 async/awaitHow to dispatch a Redux action with a timeout?How to wait for redux thunk to dispatch actionredux-thunk dispatch method fires undefined actionSagas not triggering other sagas and actionsRedux Saga not triggering API call when action is dispatchedredux-saga Network Error - OPTIONS requestDispatching an in-progress action in ReduxReact Native redux saga yield not working on first actionWait for redux action to finish dispatching when using redux saga
(algebraic topology) question about the cellular approximation theorem
Is `curl something | sudo bash -` a reasonably safe installation method?
As a DM, how to avoid unconscious metagaming when dealing with a high AC character?
What exactly is the Tension force?
Can someone explain this logical statement?
3D-Plot with an inequality condition for parameter values
Nested-Loop-Join: How many comparisons and how many pages-accesses?
Construct a pentagon avoiding compass use
What is this old "lemon-squeezer" shaped pan
Are villager price increases due to killing them temporary?
Behavior of the zero and negative/sign flags on classic instruction sets
Why is "dark" an adverb in this sentence?
Why does ffmpeg choose 10+20+20ms instead of an even 16ms for 60fps gifs?
Why use null function instead of == []
Commutator subgroup of Heisenberg group.
Can I activate an iPhone without an Apple ID?
how to generate correct single and double quotes in tex
Does entangle require vegetation?
Relationship between GCD, LCM and the Riemann Zeta function
Why do candidates not quit if they no longer have a realistic chance to win in the 2020 US presidents election
What impact would a dragon the size of Asia have on the environment?
Won 50K! Now what should I do with it
Why is dry soil hydrophobic? Bad gardener paradox
Published paper containing well-known results
Waiting for call to finish and then dispatch action in saga
Pros/cons of using redux-saga with ES6 generators vs redux-thunk with ES2017 async/awaitHow to dispatch a Redux action with a timeout?How to wait for redux thunk to dispatch actionredux-thunk dispatch method fires undefined actionSagas not triggering other sagas and actionsRedux Saga not triggering API call when action is dispatchedredux-saga Network Error - OPTIONS requestDispatching an in-progress action in ReduxReact Native redux saga yield not working on first actionWait for redux action to finish dispatching when using redux saga
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to make call to server and then use that data for dispatch of other action.
export function* function1(actions)
console.log('inside');
try
console.log('getting past orders list');
const url = `/api/getOrders`;
let reqsData =
order_id: actions.payload.order_id
;
const data = yield call(request, url, method: 'POST', data:reqsData )
console.log(data);
console.log('///////////////////////////////////');
if (!data.error)
console.log(data)
yield put( type: 'nowThis', payload: actions.payload.data );
else
console.log('---------------------------------')
console.log('got some error');
catch (error)
console.log(error)
But It is not running code next to line
const data = yield call(request, url, method: 'POST', data:reqsData )
I have similar code before which is running properly + i checked the network and i am getting response 200 for this line.
I have used fork in place of call but it run my code next to that line before the call is complete.
reactjs redux redux-saga
|
show 2 more comments
I want to make call to server and then use that data for dispatch of other action.
export function* function1(actions)
console.log('inside');
try
console.log('getting past orders list');
const url = `/api/getOrders`;
let reqsData =
order_id: actions.payload.order_id
;
const data = yield call(request, url, method: 'POST', data:reqsData )
console.log(data);
console.log('///////////////////////////////////');
if (!data.error)
console.log(data)
yield put( type: 'nowThis', payload: actions.payload.data );
else
console.log('---------------------------------')
console.log('got some error');
catch (error)
console.log(error)
But It is not running code next to line
const data = yield call(request, url, method: 'POST', data:reqsData )
I have similar code before which is running properly + i checked the network and i am getting response 200 for this line.
I have used fork in place of call but it run my code next to that line before the call is complete.
reactjs redux redux-saga
Is it breaking on that line ? does it goes to catch block ? if yes, then can you share the error.
– Fawaz
Mar 26 at 6:39
@Fawaz Not it is not throwing any error and in network section of browser I have checked the response of request200
– Rajan Lagah
Mar 26 at 6:47
Check in the console section of browser, the console log of your catch block.
– Fawaz
Mar 26 at 6:49
@Fawaz it is not printing anything in .catch but in .then i am getting response
– Rajan Lagah
Mar 26 at 6:50
Could you add an example of how you use the saga outside ?
– Bear-Foot
Mar 26 at 6:59
|
show 2 more comments
I want to make call to server and then use that data for dispatch of other action.
export function* function1(actions)
console.log('inside');
try
console.log('getting past orders list');
const url = `/api/getOrders`;
let reqsData =
order_id: actions.payload.order_id
;
const data = yield call(request, url, method: 'POST', data:reqsData )
console.log(data);
console.log('///////////////////////////////////');
if (!data.error)
console.log(data)
yield put( type: 'nowThis', payload: actions.payload.data );
else
console.log('---------------------------------')
console.log('got some error');
catch (error)
console.log(error)
But It is not running code next to line
const data = yield call(request, url, method: 'POST', data:reqsData )
I have similar code before which is running properly + i checked the network and i am getting response 200 for this line.
I have used fork in place of call but it run my code next to that line before the call is complete.
reactjs redux redux-saga
I want to make call to server and then use that data for dispatch of other action.
export function* function1(actions)
console.log('inside');
try
console.log('getting past orders list');
const url = `/api/getOrders`;
let reqsData =
order_id: actions.payload.order_id
;
const data = yield call(request, url, method: 'POST', data:reqsData )
console.log(data);
console.log('///////////////////////////////////');
if (!data.error)
console.log(data)
yield put( type: 'nowThis', payload: actions.payload.data );
else
console.log('---------------------------------')
console.log('got some error');
catch (error)
console.log(error)
But It is not running code next to line
const data = yield call(request, url, method: 'POST', data:reqsData )
I have similar code before which is running properly + i checked the network and i am getting response 200 for this line.
I have used fork in place of call but it run my code next to that line before the call is complete.
reactjs redux redux-saga
reactjs redux redux-saga
asked Mar 26 at 6:34
Rajan LagahRajan Lagah
8917 silver badges16 bronze badges
8917 silver badges16 bronze badges
Is it breaking on that line ? does it goes to catch block ? if yes, then can you share the error.
– Fawaz
Mar 26 at 6:39
@Fawaz Not it is not throwing any error and in network section of browser I have checked the response of request200
– Rajan Lagah
Mar 26 at 6:47
Check in the console section of browser, the console log of your catch block.
– Fawaz
Mar 26 at 6:49
@Fawaz it is not printing anything in .catch but in .then i am getting response
– Rajan Lagah
Mar 26 at 6:50
Could you add an example of how you use the saga outside ?
– Bear-Foot
Mar 26 at 6:59
|
show 2 more comments
Is it breaking on that line ? does it goes to catch block ? if yes, then can you share the error.
– Fawaz
Mar 26 at 6:39
@Fawaz Not it is not throwing any error and in network section of browser I have checked the response of request200
– Rajan Lagah
Mar 26 at 6:47
Check in the console section of browser, the console log of your catch block.
– Fawaz
Mar 26 at 6:49
@Fawaz it is not printing anything in .catch but in .then i am getting response
– Rajan Lagah
Mar 26 at 6:50
Could you add an example of how you use the saga outside ?
– Bear-Foot
Mar 26 at 6:59
Is it breaking on that line ? does it goes to catch block ? if yes, then can you share the error.
– Fawaz
Mar 26 at 6:39
Is it breaking on that line ? does it goes to catch block ? if yes, then can you share the error.
– Fawaz
Mar 26 at 6:39
@Fawaz Not it is not throwing any error and in network section of browser I have checked the response of request
200
– Rajan Lagah
Mar 26 at 6:47
@Fawaz Not it is not throwing any error and in network section of browser I have checked the response of request
200
– Rajan Lagah
Mar 26 at 6:47
Check in the console section of browser, the console log of your catch block.
– Fawaz
Mar 26 at 6:49
Check in the console section of browser, the console log of your catch block.
– Fawaz
Mar 26 at 6:49
@Fawaz it is not printing anything in .catch but in .then i am getting response
– Rajan Lagah
Mar 26 at 6:50
@Fawaz it is not printing anything in .catch but in .then i am getting response
– Rajan Lagah
Mar 26 at 6:50
Could you add an example of how you use the saga outside ?
– Bear-Foot
Mar 26 at 6:59
Could you add an example of how you use the saga outside ?
– Bear-Foot
Mar 26 at 6:59
|
show 2 more comments
2 Answers
2
active
oldest
votes
yield call takes function and arguments. Write a method to make a service call. U can use axios npm package (axios.get('../url',params:params)) and call that function in yield call.
yield call(methodToCallApi(),params,to,method). also, it is better if you keep services calls in a seperate file and just call those methods in saga, instead of defining directly in saga.
add a comment |
It seems your request
method is not returning properly. Wrap that in a Promise
:
request()
return new Promise(resolve =>
myApiCall().then(response =>
resolve(response);
).catch(e =>
reject(e);
);
);
and then in your saga, you can yield
as normal:
const data = yield call(request, url, method: 'POST', data:reqsData )
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55351087%2fwaiting-for-call-to-finish-and-then-dispatch-action-in-saga%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
yield call takes function and arguments. Write a method to make a service call. U can use axios npm package (axios.get('../url',params:params)) and call that function in yield call.
yield call(methodToCallApi(),params,to,method). also, it is better if you keep services calls in a seperate file and just call those methods in saga, instead of defining directly in saga.
add a comment |
yield call takes function and arguments. Write a method to make a service call. U can use axios npm package (axios.get('../url',params:params)) and call that function in yield call.
yield call(methodToCallApi(),params,to,method). also, it is better if you keep services calls in a seperate file and just call those methods in saga, instead of defining directly in saga.
add a comment |
yield call takes function and arguments. Write a method to make a service call. U can use axios npm package (axios.get('../url',params:params)) and call that function in yield call.
yield call(methodToCallApi(),params,to,method). also, it is better if you keep services calls in a seperate file and just call those methods in saga, instead of defining directly in saga.
yield call takes function and arguments. Write a method to make a service call. U can use axios npm package (axios.get('../url',params:params)) and call that function in yield call.
yield call(methodToCallApi(),params,to,method). also, it is better if you keep services calls in a seperate file and just call those methods in saga, instead of defining directly in saga.
answered Mar 26 at 6:55
Gaurav MithasGaurav Mithas
13 bronze badges
13 bronze badges
add a comment |
add a comment |
It seems your request
method is not returning properly. Wrap that in a Promise
:
request()
return new Promise(resolve =>
myApiCall().then(response =>
resolve(response);
).catch(e =>
reject(e);
);
);
and then in your saga, you can yield
as normal:
const data = yield call(request, url, method: 'POST', data:reqsData )
add a comment |
It seems your request
method is not returning properly. Wrap that in a Promise
:
request()
return new Promise(resolve =>
myApiCall().then(response =>
resolve(response);
).catch(e =>
reject(e);
);
);
and then in your saga, you can yield
as normal:
const data = yield call(request, url, method: 'POST', data:reqsData )
add a comment |
It seems your request
method is not returning properly. Wrap that in a Promise
:
request()
return new Promise(resolve =>
myApiCall().then(response =>
resolve(response);
).catch(e =>
reject(e);
);
);
and then in your saga, you can yield
as normal:
const data = yield call(request, url, method: 'POST', data:reqsData )
It seems your request
method is not returning properly. Wrap that in a Promise
:
request()
return new Promise(resolve =>
myApiCall().then(response =>
resolve(response);
).catch(e =>
reject(e);
);
);
and then in your saga, you can yield
as normal:
const data = yield call(request, url, method: 'POST', data:reqsData )
answered Mar 26 at 7:28
FawazFawaz
1,5442 gold badges11 silver badges14 bronze badges
1,5442 gold badges11 silver badges14 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55351087%2fwaiting-for-call-to-finish-and-then-dispatch-action-in-saga%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is it breaking on that line ? does it goes to catch block ? if yes, then can you share the error.
– Fawaz
Mar 26 at 6:39
@Fawaz Not it is not throwing any error and in network section of browser I have checked the response of request
200
– Rajan Lagah
Mar 26 at 6:47
Check in the console section of browser, the console log of your catch block.
– Fawaz
Mar 26 at 6:49
@Fawaz it is not printing anything in .catch but in .then i am getting response
– Rajan Lagah
Mar 26 at 6:50
Could you add an example of how you use the saga outside ?
– Bear-Foot
Mar 26 at 6:59