( props: DeckGLProps<ViewsT>, ref: React.Ref<DeckGLRef<ViewsT>> )
| 111 | } |
| 112 | |
| 113 | function DeckGLWithRef<ViewsT extends ViewOrViews = null>( |
| 114 | props: DeckGLProps<ViewsT>, |
| 115 | ref: React.Ref<DeckGLRef<ViewsT>> |
| 116 | ) { |
| 117 | // A mechanism to force redraw |
| 118 | const [version, setVersion] = useState(0); |
| 119 | // A reference to persistent states |
| 120 | const _thisRef = useRef<DeckInstanceRef<ViewsT>>({ |
| 121 | control: null, |
| 122 | version, |
| 123 | forceUpdate: () => setVersion(v => v + 1) |
| 124 | }); |
| 125 | const thisRef = _thisRef.current; |
| 126 | // DOM refs |
| 127 | const containerRef = useRef(null); |
| 128 | const canvasRef = useRef(null); |
| 129 | |
| 130 | // extract any deck.gl layers masquerading as react elements from props.children |
| 131 | const jsxProps = useMemo( |
| 132 | () => extractJSXLayers(props), |
| 133 | [props.layers, props.views, props.children] |
| 134 | ); |
| 135 | |
| 136 | // Callbacks |
| 137 | let inRender = true; |
| 138 | |
| 139 | const handleViewStateChange: DeckProps<ViewsT>['onViewStateChange'] = params => { |
| 140 | if (inRender && props.viewState) { |
| 141 | // Callback may invoke a state update. Defer callback to after render() to avoid React error |
| 142 | // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once |
| 143 | // Store deferred parameters in ref so that we can access it in another render |
| 144 | thisRef.viewStateUpdateRequested = params; |
| 145 | return null; |
| 146 | } |
| 147 | thisRef.viewStateUpdateRequested = null; |
| 148 | return props.onViewStateChange?.(params); |
| 149 | }; |
| 150 | |
| 151 | const handleInteractionStateChange: DeckProps<ViewsT>['onInteractionStateChange'] = params => { |
| 152 | if (inRender) { |
| 153 | // Callback may invoke a state update. Defer callback to after render() to avoid React error |
| 154 | // In React StrictMode, render is executed twice and useEffect/useLayoutEffect is executed once |
| 155 | // Store deferred parameters in ref so that we can access it in another render |
| 156 | thisRef.interactionStateUpdateRequested = params; |
| 157 | } else { |
| 158 | thisRef.interactionStateUpdateRequested = null; |
| 159 | props.onInteractionStateChange?.(params); |
| 160 | } |
| 161 | }; |
| 162 | |
| 163 | // Update Deck's props. If Deck needs redraw, this will trigger a call to `_customRender` in |
| 164 | // the next animation frame. |
| 165 | // Needs to be called both from initial mount, and when new props are received |
| 166 | const deckProps = useMemo(() => { |
| 167 | const forwardProps: DeckProps<ViewsT> = { |
| 168 | widgets: [], |
| 169 | ...props, |
| 170 | // Override user styling props. We will set the canvas style in render() |
nothing calls this directly
no test coverage detected
searching dependent graphs…