Replies: 3 comments 4 replies
-
Nice pattern. Thanks for using my packages! Getting types when you're going to a specific named action is fine, like your My pattern is typically to redirect on success and only return on validation failures or throw Response on anything else. So I guess if you're using named actions and only return validation errors, then you won't need to worry too much about typing |
Beta Was this translation helpful? Give feedback.
-
The I recommend you to add a property to the response so you can treat it as a discriminated union and do something like this: let actionData = useActionData<typeof action>()
if (actionData.type === "SAVE_DOCUMENT") {
// do something with a SAVE_DOCUMENT action response
}
// more conditions here |
Beta Was this translation helpful? Give feedback.
-
thank you guys for you comments and great packages! |
Beta Was this translation helpful? Give feedback.
-
I've been using remix daily for the past 1.5 years now, greatly enjoying the ideas, DX and productivity all around.
Developing in Remix for me is a quest for elegant patterns to ensure quality software, typescript and zod are a big part of the thing.
One thing i've yet to find a really elegant solution for is multi action routes, specifically:
useActionData
orfetcher.data
fetcher.submission
(for optimistic ui)I've tried a few patterned to get the desired result, but havn't found a nice one that feels covers all bases
@sergiodxa great
remix-utils
hasnamed-actions
that really comes close, but the subaction handlers are defined inside the main remix function so can't be used to typing in the components meaning inuseActionData<typeof mySubActionFunc>
,mySubActionFunc
isn't defined.i'm also using @kiliman's
remix-params-helper
andremix-typedjson
and @airjp73remix-validated-form
quite a lotI really feel like this type of scenario is at the core of any non trivial routes and Remix and the community can come up with a nice solid pattern.
My latest iteration on this is something along these lines (note: this almost works with remix-utils, just need to pass ActionArgs to the sub action handlers, a little PR and we're there):
Hope this was clear enough,
I'd really love to hear your take on this, what are you using for routes with lot's of sub actions ?
Beta Was this translation helpful? Give feedback.
All reactions