Skip to content

Inconsistency in clearing state.error in the Advanced Tutorial #744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dwiyatci opened this issue Sep 27, 2020 · 3 comments
Closed

Inconsistency in clearing state.error in the Advanced Tutorial #744

dwiyatci opened this issue Sep 27, 2020 · 3 comments

Comments

@dwiyatci
Copy link

Hi again! :)) I noticed that in the Advanced Tutorial, the state.error for issues slice and comments slice are being cleared inconsistently.

What would be the best place to clear the error state in order to make it consistent when dealing with async requests? Would it be enough to clear it in the "pending" reducers only? 🤔

@akursat
Copy link

akursat commented Oct 15, 2020

The "pending" state is about loading not about error.
success:
state.loading = false
state.error = null
failure:
state.loading = false
state.error = payload
pending:
state.loading = true

@dwiyatci
Copy link
Author

@akursat Hm yeah, I guess that's one way to look at it. 🙂 But imagine state.error is used to render an error message. Then you would want to clear it as soon as you make a request to the network (as it enters the pending reducer), otherwise the error message will still be shown along with the loading spinner until the network comes back to you with a result (either fulfilled or rejected).

So this formulation may well also be desirable:

pending: (state) => {
  state.loading = true;
  state.error = null;
},
fulfilled: (state) => {
  state.loading = false;
},
rejected: (state, action) => {
  state.loading = false;
  state.error = action.payload;
}

@markerikson
Copy link
Collaborator

Obsolete due to #905 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants