Should I get data from APi or should I just pass it through actions?
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
add a comment |
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
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
add a comment |
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
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
reactjs rest redux
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
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
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%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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
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%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
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
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