And inside the useEffect, we define a local variable treeData,
we pass this treeData also with nodeConfigsTreeData to our Filter function searchTreeDataWithHandleDataType
and update the treeData by the function's return value
- Here is quite essential, because before the searchTreeDataWithHandleDataType() has no return value- and the treeData we used in the filter function is the global 'treeData'
after we have a local variable treeData , we could modify in if without interrupting the global 'treeData'
and no matter what we setTreeData([...treeData, commandsToTreeData])
This is exactly, adding commandTreeData only after filtering(when we need filter)
Former Mistakes:
**before in our filter function,
we don't take in treeData as params, but use the global treeData from body directly, making the function 'leaking'
we setTreeData in filterFunction directly, and this would infect global treedata
After adding a local variable, we could do the filtering and only affect local
And we can set the FilteredTreeData only when we want**
We have two treeData in the code:
- Here is quite essential, because before the searchTreeDataWithHandleDataType() has no return value - and the treeData we used in the filter function is the global 'treeData'
Former Mistakes: