Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit 56480cd

Browse files
committed
fix: remove side effects in getDerivedStateFromProps
1 parent a6e02ed commit 56480cd

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/react-sortable-tree.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,16 @@ class ReactSortableTree extends Component {
280280
static getDerivedStateFromProps(nextProps, prevState) {
281281
const { instanceProps } = prevState
282282
const newState = {}
283+
const newInstanceProps = { ...instanceProps }
283284

284285
const isTreeDataEqual = isEqual(instanceProps.treeData, nextProps.treeData)
285286

286287
// make sure we have the most recent version of treeData
287-
instanceProps.treeData = nextProps.treeData
288+
newInstanceProps.treeData = nextProps.treeData
288289

289290
if (!isTreeDataEqual) {
290291
if (instanceProps.ignoreOneTreeUpdate) {
291-
instanceProps.ignoreOneTreeUpdate = false
292+
newInstanceProps.ignoreOneTreeUpdate = false
292293
} else {
293294
newState.searchFocusTreeIndex = undefined
294295
ReactSortableTree.loadLazyChildren(nextProps, prevState)
@@ -317,9 +318,9 @@ class ReactSortableTree extends Component {
317318
)
318319
}
319320

320-
instanceProps.searchQuery = nextProps.searchQuery
321-
instanceProps.searchFocusOffset = nextProps.searchFocusOffset
322-
newState.instanceProps = { ...instanceProps, ...newState.instanceProps }
321+
newInstanceProps.searchQuery = nextProps.searchQuery
322+
newInstanceProps.searchFocusOffset = nextProps.searchFocusOffset
323+
newState.instanceProps = { ...newInstanceProps, ...newState.instanceProps }
323324

324325
return newState
325326
}

0 commit comments

Comments
 (0)