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

                      How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                      Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?