MCPcopy
hub / github.com/TanStack/query / clientOnly

Function clientOnly

packages/solid-query-devtools/src/clientOnly.tsx:17–43  ·  view source on GitHub ↗
(
  fn: () => Promise<{
    default: T
  }>,
)

Source from the content-addressed store, hash-verified

15 https://github.com/solidjs/solid-start/blob/2967fc2db3f0df826f061020231dbdafdfa0746b/packages/start/islands/clientOnly.tsx
16*/
17export default function clientOnly<T extends Component<any>>(
18 fn: () => Promise<{
19 default: T
20 }>,
21) {
22 if (isServer)
23 return (props: ComponentProps<T> & { fallback?: JSX.Element }) =>
24 props.fallback
25
26 const [comp, setComp] = createSignal<T>()
27 fn().then((m) => setComp(() => m.default))
28 return (props: ComponentProps<T>) => {
29 let Comp: T | undefined
30 let m: boolean
31 const [, rest] = splitProps(props, ['fallback'])
32 if ((Comp = comp()) && !sharedConfig.context) return Comp(rest)
33 const [mounted, setMounted] = createSignal(!sharedConfig.context)
34 onMount(() => setMounted(true))
35 return createMemo(
36 () => (
37 (Comp = comp()),
38 (m = mounted()),
39 untrack(() => (Comp && m ? Comp(rest) : props.fallback))
40 ),
41 )
42 }
43}

Callers 1

index.tsxFile · 0.85

Calls 1

fnFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…