Feature: enable data components to have their own loader and actions #2926
Replies: 8 comments 2 replies
-
I believe we should have marked this resolved when we introduced resource routes! 🎉 Let me know if I misread the issue, but I think that's exactly what you were looking for here. |
Beta Was this translation helpful? Give feedback.
-
Resource routes sort of solve it in another way, and perhaps make the suggestion less valuable. |
Beta Was this translation helpful? Give feedback.
-
This has come up a few times with various ideas. I'll move this over to discussions so we can try to consolidate until we come up with a solution here. |
Beta Was this translation helpful? Give feedback.
-
I have the component data POC I created. You still have to use the route loader/action as the entry point for the component though. But it does support component level Error/Catch boundaries. I think the new deferred loaders that's coming soon would make this even more interesting. |
Beta Was this translation helpful? Give feedback.
-
I think loader/action with component will be great. Because many websites have many components in one route but have not many nested routes. |
Beta Was this translation helpful? Give feedback.
-
What's the latest here? |
Beta Was this translation helpful? Give feedback.
-
Any updates? |
Beta Was this translation helpful? Give feedback.
-
another discuss: #5383 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have lots of what I might call data-routes. They aren't actual routes with a URL, but they are discrete data components which require and mutate data, then pass it down to dumb components in the tree.
I think it would be useful for each data-route to have it's own loader and action.
Imagine a blogging app as an example: The main data in route
/blogs/$blogid
would be the blog post, if that errors loading data you want to throw a 404, but the blog post route has other components like comments, polls, a game users play, user uploads, authentication.. None of them are routes but each of them could error (maybe they all call 3rd party APIs) and you'd not want to throw a 404, you'd want to the component to show some sort of error state alongside the other properly functioning components in the route. It's the same with data mutations, the comments component will handle comments mutations, the polls component polls mutations etc. This would be easier to do if each was a what we might call a "data-route" with it's own loader and action functions.This would also make these components easier to reuse.
Various proposed solutions in Discord:
Ryan Florence
"create function per component that receives any required param and do the data fetching, that function shouldn’t throw an error, instead it should return an object saying if it was a success or failure and the data or error, then in the route loader you call those functions and return the result as is, you don’t do anything to handle the errors, in your route component you call useLoaderData and pass each key which, should have the data of a single component, to each component so they can check if it was an error or not show a different UI"
Kent C Dodds
"create a hidden input on the form to identify it in the parent route action":
Beta Was this translation helpful? Give feedback.
All reactions