types for useActionData #8616
zwhitchcox
started this conversation in
Show and tell / tips
Replies: 3 comments 4 replies
-
If you use the ![]() |
Beta Was this translation helpful? Give feedback.
3 replies
-
To solve this you can throw the response instead of returning it. That way useActionData only gets the inferred type from the success path
|
Beta Was this translation helpful? Give feedback.
1 reply
-
i have same issue, so everytime returning value must have a same object structure. for example if error
if success
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We've all had the scenario where we an action like this:
but of course when you use this like in the following code:
you get a type error like:
So, now you have to bloat your action with:
or you have to manually create the type:
...neither of these options provide a particularly great DX.
So, my solution is to make all properties optional:
with
useOptionalActionData
,becomes
which is probably about what you would type out yourself.
I've just started this, so can't so it's tested very thoroughly, but it seems to work.
I wanted to post my solution, so that by Cunningham's Law someone might provide a better one.
So, I'd love to see how other people in the community have solved this. Please post below 👇🏻
Beta Was this translation helpful? Give feedback.
All reactions