-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix loading state for account history #1672
Comments
@piyalbasu @CassioMG off the cuff, what do you all think of this data fetching pattern? My thinking is that when we fetch data that must be as fresh as possible, like history, we should avoid keeping the state in a store because it requires manual resetting/cleaning up of store state. A hook to do the same thing can "piggy-back" on the react component lifecycle and requires no clean up but provides us the same reusability. |
@aristidesstaffieri I like your approach of modeling the loading state with more values, I think it's a nice improvement. I have a few questions and suggestions below.
Could we display a little spinner ON TOP of the Transactions List instead of replacing the whole list with a Loader component while things are loading? This way users would never lose sight of the existing transactions, meaning it'd be a little less disruptive from a UX perspective How do we feel about using an object instead of an enum to represent the request status? Something like:
I think either way works fine, but since we have only a few different possibilities in regards to a request response I personally find the ergonomics of the object a little better so we could simply check The hook would look like this with the object approach:
What do you guys think? |
yeah so for history, there are no existing transactions since we load the data with every render of the page. I think every consuming component can choose what arrangement of loading state to use to trigger the loader but in the case of history I think it works to show a loader for the idle and loading state so that the end use experience is that the user sees a loader and then the history without an intermediary glitch.
Yeah I think I see what you're after with the object. Typically in React it's not recommended to model your state for I think we can get something similar though by using some type constraints and switching the state to a
The use of I'm not sure if we really need
What do you think of all of this? |
ah, I see what you mean. We won't have a persistent data to be shown while the new fetch is in progress and this would result in a UI glitch. Makes sense! I now also better understand what the
yeah we don't really need it, it was more like a convenient prop so we wouldn't need the extra helper. But with the reducer approach I agree that having this extra I like the reducer approach, it seems more robust and reliable than the other approach. :) |
Ah yeah sorry I should have explained that better. Yeah I think |
Problem:
The account history page suffers from a jittery loading state. The reason this happens is because we model the loading state with a boolean, and this value is initialized as
false
then set totrue
while history data is being fetched, then set tofalse
after the response is handled.Potential Solutions:
We can "fix" this with a one line change, initializing the loading flag to
true
.This improves the UX but makes the code brittle and less understandable. We can improve this by modeling our data fetching state differently, for example -
We could model our loading state more accurately with something like
and we could write a hook that is reusable and encapsulates the loading/error/data logic, a simplified version could be -
Then the loading state can be applied in the view more accurately and better communicate what it should be like -
The text was updated successfully, but these errors were encountered: