Is It Possible To Pass An Extra Parameter To A Form Action?

I'm trying to do this:
const userId = getUserId();

return (
<form action={deleteUser(userId) method="post">
<button>Delete User</button>
</form>
);
const userId = getUserId();

return (
<form action={deleteUser(userId) method="post">
<button>Delete User</button>
</form>
);
Here's the action:
export const deleteUser = action(async (userId: string) => {
await auth.deleteAccount(userId);
});
export const deleteUser = action(async (userId: string) => {
await auth.deleteAccount(userId);
});
I keep getting the following errors on the "action" of the form: Type 'Action<[userId: string], void>' is not assignable to type 'string | SerializableAttributeValue | undefined'.ts(2322) The expected type comes from property 'action' which is declared here on type 'FormHTMLAttributes<HTMLFormElement>' (property) JSX.FormHTMLAttributes<HTMLFormElement>.action?: string | JSX.SerializableAttributeValue | undefined
2 Replies
bigmistqke
bigmistqke6mo ago
action={deleteUser(userId)} will immediately execute that function and set the return value as the attribute, so I don't think that is what you are looking for. I think I saw once on a stream action={deleteUser.with(userId} but I can not seem to find documentation on it. found it https://docs.solidjs.com/solid-router/reference/data-apis/action
A with method can be used when typed data is required. This removes the need to use FormData or other additional hidden fields. The with method works similar to bind, which applies the arguments in order.
ChrisThornham
ChrisThornhamOP6mo ago
Thanks! I'll give that a try.
Want results from more Discord servers?
Add your server