MCPcopy Create free account
hub / github.com/TanStack/devtools / clientOnly

Function clientOnly

packages/solid-devtools/src/client-only.ts:17–45  ·  view source on GitHub ↗
(
  fn: () => Promise<{
    default: T
  }>,
  options: { lazy?: boolean } = {},
)

Source from the content-addressed store, hash-verified

15 */
16// not using Suspense
17export default function clientOnly<T extends Component<any>>(
18 fn: () => Promise<{
19 default: T
20 }>,
21 options: { lazy?: boolean } = {},
22) {
23 if (isServer)
24 return (props: ComponentProps<T> & { fallback?: JSX.Element }) =>
25 props.fallback
26
27 const [comp, setComp] = createSignal<T>()
28 !options.lazy && load(fn, setComp)
29 return (props: ComponentProps<T>) => {
30 let Comp: T | undefined
31 let m: boolean
32 const [, rest] = splitProps(props, ['fallback'])
33 options.lazy && load(fn, setComp)
34 if ((Comp = comp()) && !sharedConfig.context) return Comp(rest)
35 const [mounted, setMounted] = createSignal(!sharedConfig.context)
36 onMount(() => setMounted(true))
37 return createMemo(
38 () => (
39 (Comp = comp()),
40 (m = mounted()),
41 untrack(() => (Comp && m ? Comp(rest) : props.fallback))
42 ),
43 )
44 }
45}
46
47function load<T>(
48 fn: () => Promise<{

Callers 1

devtools.tsxFile · 0.85

Calls 1

loadFunction · 0.85

Tested by

no test coverage detected