Install using bunx shadcn@latest add @remix-utils/named-action.
Note
This depends on React Router.
It's common to need to handle more than one action in the same route, there are many options here like sending the form to a resource route or using an action reducer, the namedAction function uses some conventions to implement the action reducer pattern.
You can pass a FormData object to the namedAction, then it will try to find a field named intent and use the value as the action name.
If, in any case, the action name is not found, the actionName then the library will try to call an action named default, similar to a switch in JavaScript.
If the default is not defined it will throw a ReferenceError with the message Action "${name}" not found.
If the library couldn't found the name at all, it will throw a ReferenceError with the message Action name not found
Install using
bunx shadcn@latest add @remix-utils/named-action.This depends on React Router.
It's common to need to handle more than one action in the same route, there are many options here like sending the form to a resource route or using an action reducer, the
namedActionfunction uses some conventions to implement the action reducer pattern.This function can follow this convention:
You can pass a FormData object to the
namedAction, then it will try to find a field namedintentand use the value as the action name.If, in any case, the action name is not found, the
actionNamethen the library will try to call an action nameddefault, similar to aswitchin JavaScript.If the
defaultis not defined it will throw a ReferenceError with the messageAction "${name}" not found.If the library couldn't found the name at all, it will throw a ReferenceError with the message
Action name not foundAuthor
Sergio XalambrÃ