S
SolidJSโ€ข2y ago
binajmen

How to retrieve params in `createServerAction$`?

Is there a clever way to retrieve the params in a createServerAction$ besides passing it as a parameter or FormData attribute?
const [create, { Form }] = createServerAction$(async (formData: FormData) => {
...
});
const [create, { Form }] = createServerAction$(async (formData: FormData) => {
...
});
8 Replies
binajmen
binajmenOPโ€ข2y ago
up? ๐Ÿ˜‡
Alex Lohr
Alex Lohrโ€ข2y ago
does useParams() not work?
binajmen
binajmenOPโ€ข2y ago
I don't think so. I can't use useParams() in server action, and if I declare it outside and try to use it, I get a closure issue (params not defined). Too bad we don't have access to params. We do have access to request though in the ActionEvent:
export function createRouteAction<T, U = void>(
fn: (args: T, event: ActionEvent) => Promise<U>,
options?: { invalidate?: Invalidate }
): RouteAction<T, U>;
export function createRouteAction<T, U = void>(
fn: (args: T, event: ActionEvent) => Promise<U>,
options?: { invalidate?: Invalidate }
): RouteAction<T, U>;
I wonder why we don't have params there.
Alex Lohr
Alex Lohrโ€ข2y ago
In that case, you need the request object's url part parsed through new URL(). The resulting objects has searchParams as a property.
binajmen
binajmenOPโ€ข2y ago
True ๐Ÿ™‚ I wanted to be sure I don't miss something, I feel having params there would be handy ๐Ÿ™‚
Unknown User
Unknown Userโ€ข2y ago
Message Not Public
Sign In & Join Server To View
binajmen
binajmenOPโ€ข2y ago
GitHub
Access params in createServerAction$? ยท Discussion #551 ยท solid...
The same way we have access to request, it would be nice to have access to params as well: -const [create, { Form }] = createServerAction$(async (formData: FormData, { request }) =&gt; { +const...
binajmen
binajmenOPโ€ข2y ago
I feel I spammed the discussions section recently, but I spent the weekend trying Solid. Loving it so far! Except the i18n. I didn't manage to make the primitives package work around SolidStart... yet!
Want results from more Discord servers?
Add your server