Skip to content
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

[DataGrid] Fix loader flag from useDemoData hook #1279

Merged
merged 2 commits into from
Mar 25, 2021

Conversation

DanailH
Copy link
Member

@DanailH DanailH commented Mar 23, 2021

Fixes #1276

@DanailH DanailH added bug 🐛 Something doesn't work docs Improvements or additions to the documentation labels Mar 23, 2021
@DanailH DanailH self-assigned this Mar 23, 2021
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rational behind solving the problem with this approach? I mean, in the initial render, it means that the rows are empty and the loading state is false. Is it expected? It seems wrong.

@DanailH
Copy link
Member Author

DanailH commented Mar 24, 2021

OK if you look it that way then yes you are correct - when opening it initially technically the data is loading. The problem was that when you change pages the self invoked function is not being called.

I'm ok if we say that the loading state is true. It's just a different way of looking at the problem.

@oliviertassinari Updated

@@ -82,7 +82,7 @@ export const useDemoData = (options: DemoDataOptions): DemoDataReturnType => {
const [data, setData] = React.useState<GridData>({ columns: [], rows: [] });
const [rowLength, setRowLength] = React.useState(options.rowLength);
const [index, setIndex] = React.useState(0);
const [loading, setLoading] = React.useState(false);
const [loading, setLoading] = React.useState(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that initially the rows are not loading. And the grid should be empty
And only when you get in the useEffect it starts loading.
Have you tried to remove the useEffect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand the use.Effect and what is inside is to prevent the freeze when fetching a lot of data. For me both having it by default as true and false are logical it depends on how we want to look at it.

@oliviertassinari
Copy link
Member

oliviertassinari commented Mar 24, 2021

if you look it that way

Yeah, I guess it depends on how we see it. No preferences.

What do you think about following whatever react-query do to set the loading state based on the missing data (I haven't looked)? This way we would get closer to what most developers do in their own applications, and hopefully have better constraints for handling the loading state in the data grid?

@DanailH
Copy link
Member Author

DanailH commented Mar 25, 2021

I would need to check it. I can do it after I open the PR for navigating the header cells with the keyboard. I would still like to merge this fix to have the current version working.

@oliviertassinari
Copy link
Member

oliviertassinari commented Mar 25, 2021

@DanailH In this case, I'm looking at it now, as it takes 5 minutes. https://codesandbox.io/s/relaxed-framework-p5qz7 (from https://react-query.tanstack.com/examples/simple)

Screenshot 2021-03-25 at 12 13 49

The current version looks great 👍

@DanailH
Copy link
Member Author

DanailH commented Mar 25, 2021

Ah ok, I get it, I'll update the PR and add the additional flag today.

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I get it, I'll update the PR and add the additional flag today.

What do you mean by an addition flag?

@DanailH
Copy link
Member Author

DanailH commented Mar 25, 2021

Ah ok, I get it, I'll update the PR and add the additional flag today.

What do you mean by an addition flag?

Sorry, the check to see if there is already data although isn't what if (dataCache.has(cacheKey)) does? It checks if there is cahched data.

@oliviertassinari
Copy link
Member

oliviertassinari commented Mar 25, 2021

@DanailH I don't follow. My point on using react-query as a benchmark was to find an answer to this discussion #1279 (comment).

@DanailH
Copy link
Member Author

DanailH commented Mar 25, 2021

Ok, I was left with the impression that I need to do something in addition. If that's ok then I'll just merge 😅

@DanailH DanailH merged commit c40d53f into mui:master Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[docs] Loader in demo page
3 participants