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
Madaxen86
Madaxen86•4mo ago
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.
Samual 🦢
Samual 🦢OP•4mo ago
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 it
Madaxen86
Madaxen86•4mo ago
They 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.
Samual 🦢
Samual 🦢OP•4mo ago
yeah once again, I don't want to be directly referencing specific resources either for the same reason stated above
Madaxen86
Madaxen86•4mo ago
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.
ryansolid
ryansolid•3mo ago
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.
Samual 🦢
Samual 🦢OP•3mo ago
nah don't worry I think it was user error okay so I've simplified it to
const dummyCacheThing = cache(async () => 1, "dummyCacheThing")

const [ routeData ] = createResource(() => {
dummyCacheThing()
return /* route data here */
}, v => v)

// logged on route change and form submissions
createEffect(() => console.log(routeData()))
const dummyCacheThing = cache(async () => 1, "dummyCacheThing")

const [ routeData ] = createResource(() => {
dummyCacheThing()
return /* route data here */
}, v => v)

// logged on route change and form submissions
createEffect(() => console.log(routeData()))
but I'm not too sure why this works. and why does commenting out the dummyCacheThing() line stop it from working?
Want results from more Discord servers?
Add your server