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

Update hooks.ts lastsubmission to accept null value #292

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

zifahm
Copy link
Contributor

@zifahm zifahm commented Sep 23, 2023

In Remix, there may be times when you need to return json(null), which is often what Remix expects. If you return json(undefined), the loaders are not refetched. To resolve this issue, accepting null for "lastsubmission" keeps TypeScript happy and ensures the loader is refetched.

@edmundhung
Copy link
Owner

Hi @zifahm, I would like to learn more about your usecase first. Can you tell me more what you are trying to do? That will help me understand your problem and identify if there is a better solution :)

@zifahm
Copy link
Contributor Author

zifahm commented Sep 25, 2023

I don't always use "conform" for all of my forms. I might also return "json(null)" frequently when I simply need to execute an action. However, TypeScript's type checking becomes problematic when using "json(null)" instead of "json(undefined)," and strangely, using "json(undefined)" doesn't trigger the loader to refresh for some reason. This is the scenario I'm dealing with.

As for my current workaround, I use the following code snippet:

lastSubmission: lastSubmission === null ? undefined : lastSubmission

I really don't want to have to do this repeatedly. Therefore, allowing "conform" to accept "null" values would reduce the amount of code I need to write.

Copy link
Owner

@edmundhung edmundhung left a comment

Choose a reason for hiding this comment

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

I am fine with the changes. I will do a quick check over the weekend and release it as 0.9.1 if I don't see other issue. Thanks! 👍🏼

In Remix, there may be times when you need to return JSON(null), which is often what Remix expects. If you return JSON(undefined), the loaders are not refetched. To resolve this issue, accepting null for "lastsubmission" keeps TypeScript happy and ensures the loader is refetched.
@edmundhung edmundhung merged commit 4a3433d into edmundhung:main Nov 9, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants