Should I get data from APi or should I just pass it through actions?












0















I have some data (like month ID) in frontend (React) that is used to create URL and send via POST method. It sends some info to the server and then server returns appropriate response.



I am using Redux. So in my reducer when I get the response from API I need that month ID to update state.



My question is: Is it better to send month ID as a field in the response from the API or is it better to send month ID through action argument?










share|improve this question

























  • Your reducer shouldn't handle async functions. The way I do it, is my action returns a promise that a middleware catches, solves, and sends to redux only the answer of the api call

    – iagowp
    Nov 22 '18 at 14:16











  • Ofcourse, my reducer isn't having any async calls. It gets data and works with it. I am asking which way should one field of that data (month ID) be provided.

    – nodrus
    Nov 22 '18 at 14:18
















0















I have some data (like month ID) in frontend (React) that is used to create URL and send via POST method. It sends some info to the server and then server returns appropriate response.



I am using Redux. So in my reducer when I get the response from API I need that month ID to update state.



My question is: Is it better to send month ID as a field in the response from the API or is it better to send month ID through action argument?










share|improve this question

























  • Your reducer shouldn't handle async functions. The way I do it, is my action returns a promise that a middleware catches, solves, and sends to redux only the answer of the api call

    – iagowp
    Nov 22 '18 at 14:16











  • Ofcourse, my reducer isn't having any async calls. It gets data and works with it. I am asking which way should one field of that data (month ID) be provided.

    – nodrus
    Nov 22 '18 at 14:18














0












0








0








I have some data (like month ID) in frontend (React) that is used to create URL and send via POST method. It sends some info to the server and then server returns appropriate response.



I am using Redux. So in my reducer when I get the response from API I need that month ID to update state.



My question is: Is it better to send month ID as a field in the response from the API or is it better to send month ID through action argument?










share|improve this question
















I have some data (like month ID) in frontend (React) that is used to create URL and send via POST method. It sends some info to the server and then server returns appropriate response.



I am using Redux. So in my reducer when I get the response from API I need that month ID to update state.



My question is: Is it better to send month ID as a field in the response from the API or is it better to send month ID through action argument?







reactjs rest redux






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 14:16







nodrus

















asked Nov 22 '18 at 14:13









nodrusnodrus

44




44













  • Your reducer shouldn't handle async functions. The way I do it, is my action returns a promise that a middleware catches, solves, and sends to redux only the answer of the api call

    – iagowp
    Nov 22 '18 at 14:16











  • Ofcourse, my reducer isn't having any async calls. It gets data and works with it. I am asking which way should one field of that data (month ID) be provided.

    – nodrus
    Nov 22 '18 at 14:18



















  • Your reducer shouldn't handle async functions. The way I do it, is my action returns a promise that a middleware catches, solves, and sends to redux only the answer of the api call

    – iagowp
    Nov 22 '18 at 14:16











  • Ofcourse, my reducer isn't having any async calls. It gets data and works with it. I am asking which way should one field of that data (month ID) be provided.

    – nodrus
    Nov 22 '18 at 14:18

















Your reducer shouldn't handle async functions. The way I do it, is my action returns a promise that a middleware catches, solves, and sends to redux only the answer of the api call

– iagowp
Nov 22 '18 at 14:16





Your reducer shouldn't handle async functions. The way I do it, is my action returns a promise that a middleware catches, solves, and sends to redux only the answer of the api call

– iagowp
Nov 22 '18 at 14:16













Ofcourse, my reducer isn't having any async calls. It gets data and works with it. I am asking which way should one field of that data (month ID) be provided.

– nodrus
Nov 22 '18 at 14:18





Ofcourse, my reducer isn't having any async calls. It gets data and works with it. I am asking which way should one field of that data (month ID) be provided.

– nodrus
Nov 22 '18 at 14:18












1 Answer
1






active

oldest

votes


















0














What are you using to handle async actions, redux thunk? redux saga?



Generally it's best to update the store on a successful response, as you can be more sure your new state is valid. It's also common to 'eager' update the store before the response has returned, and then revert that change if the response fails.






share|improve this answer
























  • I am using redux thunk. I just want to know which source of information is better. From the API or from the form itself.

    – nodrus
    Nov 25 '18 at 22:50











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%2f53432867%2fshould-i-get-data-from-api-or-should-i-just-pass-it-through-actions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














What are you using to handle async actions, redux thunk? redux saga?



Generally it's best to update the store on a successful response, as you can be more sure your new state is valid. It's also common to 'eager' update the store before the response has returned, and then revert that change if the response fails.






share|improve this answer
























  • I am using redux thunk. I just want to know which source of information is better. From the API or from the form itself.

    – nodrus
    Nov 25 '18 at 22:50
















0














What are you using to handle async actions, redux thunk? redux saga?



Generally it's best to update the store on a successful response, as you can be more sure your new state is valid. It's also common to 'eager' update the store before the response has returned, and then revert that change if the response fails.






share|improve this answer
























  • I am using redux thunk. I just want to know which source of information is better. From the API or from the form itself.

    – nodrus
    Nov 25 '18 at 22:50














0












0








0







What are you using to handle async actions, redux thunk? redux saga?



Generally it's best to update the store on a successful response, as you can be more sure your new state is valid. It's also common to 'eager' update the store before the response has returned, and then revert that change if the response fails.






share|improve this answer













What are you using to handle async actions, redux thunk? redux saga?



Generally it's best to update the store on a successful response, as you can be more sure your new state is valid. It's also common to 'eager' update the store before the response has returned, and then revert that change if the response fails.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 14:27









CecilCecil

22625




22625













  • I am using redux thunk. I just want to know which source of information is better. From the API or from the form itself.

    – nodrus
    Nov 25 '18 at 22:50



















  • I am using redux thunk. I just want to know which source of information is better. From the API or from the form itself.

    – nodrus
    Nov 25 '18 at 22:50

















I am using redux thunk. I just want to know which source of information is better. From the API or from the form itself.

– nodrus
Nov 25 '18 at 22:50





I am using redux thunk. I just want to know which source of information is better. From the API or from the form itself.

– nodrus
Nov 25 '18 at 22:50


















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%2f53432867%2fshould-i-get-data-from-api-or-should-i-just-pass-it-through-actions%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

Wiesbaden

Marschland

Dieringhausen