MCPcopy Create free account
hub / github.com/artsy/force / SystemQueryRenderer

Function SystemQueryRenderer

src/System/Relay/SystemQueryRenderer.tsx:40–100  ·  view source on GitHub ↗
({
  debugPlaceholder = false,
  lazyLoad = false,
  lazyLoadThreshold = 1500,
  placeholder,
  environment: _environment,
  variables = {},
  render,
  ...rest
}: SystemQueryRendererProps<T>)

Source from the content-addressed store, hash-verified

38}
39
40export function SystemQueryRenderer<T extends OperationType>({
41 debugPlaceholder = false,
42 lazyLoad = false,
43 lazyLoadThreshold = 1500,
44 placeholder,
45 environment: _environment,
46 variables = {},
47 render,
48 ...rest
49}: SystemQueryRendererProps<T>) {
50 const isMounted = useDidMount()
51
52 const [isEnteredView, setIsEnteredView] = useState(false)
53
54 const { ref } = useIntersectionObserver({
55 once: true,
56 options: {
57 threshold: 0,
58 rootMargin: `${lazyLoadThreshold}px`,
59 },
60 onIntersection: () => {
61 setIsEnteredView(true)
62 },
63 })
64
65 const showPlaceholder =
66 debugPlaceholder || !isMounted || (lazyLoad && !isEnteredView)
67
68 const { relayEnvironment } = useSystemContext()
69
70 const environment = _environment ?? relayEnvironment
71
72 if (!environment) {
73 logger.warn("Requires an environment")
74 return <></>
75 }
76
77 if (lazyLoad && showPlaceholder && isForwardRef(placeholder)) {
78 return cloneElement(placeholder, { ref: ref as any })
79 }
80
81 if (showPlaceholder) {
82 // NOTE: If your placeholder does not forwardRef we have to insert a span.
83 // It's possible that this alters the layout slightly. For instance in certain flex or grid contexts.
84 return (
85 <>
86 {lazyLoad && <span ref={ref as any} />}
87 {placeholder}
88 </>
89 )
90 }
91
92 return (
93 <QueryRenderer<T>
94 environment={environment}
95 variables={variables}
96 render={render}
97 {...rest}

Callers

nothing calls this directly

Calls 3

useDidMountFunction · 0.90
useIntersectionObserverFunction · 0.90
useSystemContextFunction · 0.90

Tested by

no test coverage detected