MCPcopy Create free account
hub / github.com/TanStack/router / useServerFn

Function useServerFn

packages/solid-start/src/useServerFn.ts:3–26  ·  view source on GitHub ↗
(
  serverFn: T,
)

Source from the content-addressed store, hash-verified

1import { isRedirect, useRouter } from '@tanstack/solid-router'
2
3export function useServerFn<T extends (...deps: Array<any>) => Promise<any>>(
4 serverFn: T,
5): (...args: Parameters<T>) => ReturnType<T> {
6 const router = useRouter()
7
8 return (async (...args: Array<any>) => {
9 try {
10 const res = await serverFn(...args)
11
12 if (isRedirect(res)) {
13 throw res
14 }
15
16 return res
17 } catch (err) {
18 if (isRedirect(err)) {
19 err.options._fromLocation = router.stores.location.get()
20 return router.navigate(router.resolveRedirect(err).options)
21 }
22
23 throw err
24 }
25 }) as any
26}

Callers 12

LoginFunction · 0.90
SignupCompFunction · 0.90
LoginFunction · 0.90
SignupCompFunction · 0.90
StatusComponentFunction · 0.90
RouteComponentFunction · 0.90
RouteComponentFunction · 0.90
SubmitPostFormDataFnFunction · 0.90
LoginFunction · 0.90
SignupCompFunction · 0.90
RedirectOnClickFunction · 0.90
RootComponentFunction · 0.90

Calls 3

useRouterFunction · 0.90
isRedirectFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected