@@ -94,7 +94,7 @@ const DeckGL = forwardRef((props, ref) => {
94
94
const _thisRef = useRef ( { } ) ;
95
95
const thisRef = _thisRef . current ;
96
96
// A mechanism to force redraw
97
- const [ , setVersion ] = useState ( 0 ) ;
97
+ const [ version , setVersion ] = useState ( 0 ) ;
98
98
thisRef . forceUpdate = setVersion ;
99
99
// DOM refs
100
100
const containerRef = useRef ( null ) ;
@@ -137,32 +137,35 @@ const DeckGL = forwardRef((props, ref) => {
137
137
// Update Deck's props. If Deck needs redraw, this will trigger a call to `_customRender` in
138
138
// the next animation frame.
139
139
// Needs to be called both from initial mount, and when new props are received
140
- const updateFromProps = ( ) => {
141
- if ( ! thisRef . deck ) {
142
- return ;
143
- }
144
- const deckProps = {
145
- ...props ,
146
- // Override user styling props. We will set the canvas style in render()
147
- style : null ,
148
- width : '100%' ,
149
- height : '100%' ,
150
- layers : jsxProps . layers ,
151
- views : jsxProps . views ,
152
- onViewStateChange : handleViewStateChange ,
153
- onInteractionStateChange : handleInteractionStateChange
154
- } ;
155
-
156
- thisRef . deck . setProps ( deckProps ) ;
157
- } ;
140
+ const deckProps = useMemo (
141
+ ( ) => {
142
+ const forwardProps = {
143
+ ...props ,
144
+ // Override user styling props. We will set the canvas style in render()
145
+ style : null ,
146
+ width : '100%' ,
147
+ height : '100%' ,
148
+ layers : jsxProps . layers ,
149
+ views : jsxProps . views ,
150
+ onViewStateChange : handleViewStateChange ,
151
+ onInteractionStateChange : handleInteractionStateChange
152
+ } ;
153
+
154
+ if ( thisRef . deck ) {
155
+ thisRef . deck . setProps ( forwardProps ) ;
156
+ }
157
+
158
+ return forwardProps ;
159
+ } ,
160
+ [ props ]
161
+ ) ;
158
162
159
163
useEffect ( ( ) => {
160
164
thisRef . deck = createDeckInstance ( thisRef , {
161
- ...props ,
165
+ ...deckProps ,
162
166
parent : containerRef . current ,
163
167
canvas : canvasRef . current
164
168
} ) ;
165
- updateFromProps ( ) ;
166
169
167
170
return ( ) => thisRef . deck . finalize ( ) ;
168
171
} , [ ] ) ;
@@ -185,8 +188,6 @@ const DeckGL = forwardRef((props, ref) => {
185
188
186
189
useImperativeHandle ( ref , ( ) => getRefHandles ( thisRef ) , [ ] ) ;
187
190
188
- updateFromProps ( ) ;
189
-
190
191
const { viewManager} = thisRef . deck || { } ;
191
192
const currentViewports = viewManager && viewManager . getViewports ( ) ;
192
193
@@ -205,11 +206,11 @@ const DeckGL = forwardRef((props, ref) => {
205
206
// before Deck redraw to ensure perfect synchronization & avoid excessive redraw
206
207
// This is because multiple changes may happen to Deck between two frames e.g. transition
207
208
if (
208
- ! thisRef . control || // initial mount
209
209
( ! thisRef . viewStateUpdateRequested && thisRef . lastRenderedViewports === currentViewports ) || // case 2
210
- thisRef . redrawReason // case 3 just before deck redraws
210
+ thisRef . version !== version // case 3 just before deck redraws
211
211
) {
212
212
thisRef . lastRenderedViewports = currentViewports ;
213
+ thisRef . version = version ;
213
214
214
215
// Render the background elements (typically react-map-gl instances)
215
216
// using the view descriptors
0 commit comments