marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
24.91k stars 5.24k forks source link

can't get application data inside the layout, remix.js useLoaderData returns undefined therein #10261

Closed justin-hackin closed 1 week ago

justin-hackin commented 2 weeks ago

What you were expecting:

I want the AppBar to match the MUI AppBar I have for the rest of my remix.js app. I want my Layout to be able to use remix loader data for the AppBar's dropdown menu.

What happened instead:

I created a custom layout, used the RA AppBar and stuffed my account icon dropdown inside there. It won't work though the useLoaderData return value is always undefined. The loader data IS present in the component that renders the Admin component.

Additional notes

For now, I'm going to delay the creation of a reproduction example because I couldn't find a remix starter example and I don't know whether this is an obvious limitation of the system or not. I suspect maybe it has something to do with RA taking over the routing.

Should this issue be a feature request to be able to pass additional props into the layout?

I tried to work around this issue using the useStore hook to set the data in the component rendering Admin and then use the value inside the panel but it seems to always be undefined inside the layout.

slax57 commented 1 week ago

Hi, and thanks for your question.

Your issue mostly looks like a "How To" request to me, rather than a bug report.

Here some elements of answer I can provide:

In any case, as explained in the react-admin contributing guide, we use the GitHub issues for bugs and feature requests only.

For support question ("How To", usage advice, or troubleshooting your own code), you have three options:

So I'm closing this issue, and inviting you to ask your question in one of the support channels above.

justin-hackin commented 1 week ago

Hi, and thanks for your question.

Your issue mostly looks like a "How To" request to me, rather than a bug report.

Here some elements of answer I can provide:

  • You can follow our Remix guide (if you have not already) to get you started with Remix and React Admin
  • To me, the best place to pass user-related data to react-admin is via the authProvider. You can for instance implement getIdentity in such a way that your user-related data is there (optionally stored in localStorage), which can then be retrieved with useGetIdentity and used to build your custom user menu
  • You could also use a React Context to expose the user data to <Admin> and its children.

In any case, as explained in the react-admin contributing guide, we use the GitHub issues for bugs and feature requests only.

For support question ("How To", usage advice, or troubleshooting your own code), you have three options:

  • Community support: Ask your question on StackOverFlow. This makes your question easy to find by the developer community. StackOverFlow has great SEO, gamification, voting, and reputation system.
  • Community support: Ask your question on Discord. Some react-admin users and contributors might have time to answer your questions.
  • Professional support: If you're a React-Admin Enterprise Edition subscriber, you have unlimited access to the Professional Support service. This service guarantees that you'll get an answer shortly. If your problem is urgent, please consider subscribing to the Enterprise Edition, starting at 125€. It's a good way to contribute to the sustainability of react-admin.

So I'm closing this issue, and inviting you to ask your question in one of the support channels above.

Whoops, sorry for my carelessness and thanks for spelling out your policy and graciously providing suggestions. This issue is low priority for me so I decided to abandon my effort to have a consistent app bar for now but if I get to it, I will report what worked here for posterity.