modern equivalent of `createRouteData()`
I'm in a solid start project and am looking for the modern equivalent of
createRouteData()
. I used to be able to use it have data that was refetched after a form was submitted. the closest modern equivalent I can find is cache()
and createAsync()
but that is very overkill and has an annoying (in this use case) feature where it caches for 1 second which means if a user is rapidly clicking a button which is rapidly submitting a form, changes can only be observed once a second rather than as soon as the user clicked.
Thanks.7 Replies
You can use
action
for form submissions which revalidates the cache. In the action you can e.g. return reload({revalidate:"yourCacheKey"})
to revalidate any specific.
And you can use useSubmission
with the action which provides errors and a pending state so you can disable the submission while one is already on the way.I don't want to be directly referencing actions
and it's not out of laziness. referencing actions directly means I can't write code that can be used generically throughout my app
also please can you link the docs page for
useSubmission()
, I can't seem to find itThey are documented with actions:
https://docs.solidjs.com/solid-router/reference/data-apis/action#action
Solution without cache and actions would be with createResource which also provides a refetch callback you can call after submission.
yeah once again, I don't want to be directly referencing specific resources either for the same reason stated above
But that’s a wrong assumption that updates can only happen once per second.
If you use actions to submit/mutate data the cache is immediately updated through the built in revalidation. There’s no delay.
And you can use actions anywhere in your code by wrapping them in the useAction helper which then provides a simple callback which also triggers revalidation.
This is the modern way solid provides.
That's interesting.. revalidation from actions should override any of the caching. The 5 second thing is just to dedupe during the length of a request but actions basicaly 0 the cache and refetch immediately. In the same way createRouteAction did it before.
cache + createAsync is the replacement. If it isn't working as expected we should look at that.
nah don't worry I think it was user error
okay so I've simplified it to
but I'm not too sure why this works. and why does commenting out the
dummyCacheThing()
line stop it from working?