Clearing form after action in solid-start
Searches on this discord return old posts that suggest using createEffect on submission.pending along with a ref to the form to do clearing.
I'm just checking if this is still the right way to handle form clearing after successful actions. Please let me know if you have a better suggestion.
Thanks
5 Replies
You can specify an
onComplete(submission)
handler on the action options which could be leveraged in that capacity.
I was added for @solidjs/router
0.15.0GitHub
solid-router/CHANGELOG.md at c05ce351b584a8db2247ddb7863915fdbfc332...
A universal router for Solid inspired by Ember and React Router - solidjs/solid-router
GitHub
solid-router/src/data/action.ts at c05ce351b584a8db2247ddb7863915fd...
A universal router for Solid inspired by Ember and React Router - solidjs/solid-router
thank you so much for taking the time to write thoughtful responses, and with reference links!
I tried out action's
onComplete
and feel that it may better belong with useSubmission
.
One reason is that having onComplete as a form clean up mechanism essentially requires it to be defined inside a component, thus the action would have to be defined inside the component as well. This makes named actions not reusable across multiple components.
Also, if an action is defined inside a component, we can do whatever form clearing or visual update (displaying error messages, success messages, etc.) inside the action async. onComplete doesn't really add value.
My 2 cents but I'm still new at this so there is a good chance this perspective is based on incomplete info.“primitives from which mechanisms can be built”I swear that needs to be Solid's motto … https://stackblitz.com/edit/stackblitz-starters-9eef3nc1?file=src%2Froutes%2Fabout.tsx,src%2Femail-action.ts
Kent Computing
YouTube
Erlang Master Class 2: Video 2 - Abstracting patterns of concurrency
http://www.cs.kent.ac.uk/ErlangMasterClasses
These Master Classes will show you how Erlang can be used in practice to solve larger problems. The examples provide 'capstones' for different aspects of Erlang: functional programming, concurrent programming and larger-scale programming with OTP.
Erlang is best known for its “share nothing” con...
StackBlitz
@solidjs/router onComplete - StackBlitz
A Solid TypeScript project based on @solidjs/meta, @solidjs/router, solid-js, typescript, vite and vite-plugin-solid
Of course I'm expecting that you will have to tailor the approach to your particular situation.
thanks. yea I got something going already. Just wanted to contribute some discussion toward slightly better dx
real, heavy duty usage probably would involved some form library any way