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;








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.










share|improve this question






















  • 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

















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.










share|improve this question






















  • 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













0












0








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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

















  • 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
















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












2 Answers
2






active

oldest

votes


















0














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.






share|improve this answer






























    0














    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 )





    share|improve this answer

























      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
      );



      );













      draft saved

      draft discarded


















      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









      0














      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.






      share|improve this answer



























        0














        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.






        share|improve this answer

























          0












          0








          0







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 6:55









          Gaurav MithasGaurav Mithas

          13 bronze badges




          13 bronze badges























              0














              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 )





              share|improve this answer



























                0














                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 )





                share|improve this answer

























                  0












                  0








                  0







                  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 )





                  share|improve this answer













                  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 )






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 26 at 7:28









                  FawazFawaz

                  1,5442 gold badges11 silver badges14 bronze badges




                  1,5442 gold badges11 silver badges14 bronze badges



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript