Overload action
Attribute Of Route To Accept Both Callable and Object Actions To Allow A Route Use More Than One Action
#11320
simonpojok
started this conversation in
Proposals
Replies: 1 comment
-
Feature-Request - only Action routes const route: RouteObject: {
path,
element,
errorElement,
loader,
action,
children: [ // see here!
{
path: 'log-employee-time-in',
action: logEmployeeTimeInAction
},
{
path: "create-employee",
action: createEmployeeAction
},
{
path: 'update-employee',
action: updateEmployeeDetail
}
]
} usage const MultipleFormsComponent = () => {
return (
<>
<p>form 1</p>
<Form action="log-employee-time-in">
...inputs
// submit will call logEmployeeTimeInAction
// and you can get useActionData from logEmployeeTimeInAction here
</Form>
...
<p>form 2</p>
<Form action="create-employee">
...inputs
// submit will call createEmployeeAction
// and you can get useActionData from createEmployeeAction here
</Form>
....
</>
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, the react-router route supports only one action, which hinders us from using more than
one form in a component. Consider the following route which works fine with just only one form.
However much solution/work arround to this exist here https://reactrouter.com/en/main/route/action#handling-multiple-actions-per-route this approach is more understandable and will require less code and zero if-else checks
Supposed that our screen is more complete and it includes more that three different forms and that architecture becomes really hard to work with,
consider the following example
I was suggesting we make action take an object where keys is the action name and value is the action callable:
bellow
ie
Beta Was this translation helpful? Give feedback.
All reactions