Updating Selected Items
The TreeView provides specific approaches for working with its data and updating the selected
field.
The available options are:
Mutating the Items Directly
The following example demonstrates how to directly update the selected items in a TreeView with single selection.
Using a Helper Function
The processTreeViewItems
helper function updates the items in an immutable way, that is, works with a copy of the data. While using processTreeViewItems
is similar to creating a copy of the data before each item update, the data
field of the application state does not change. That is why, the helper function approach is useful when other components depend on the data
field.
The following example demonstrates how to introduce an additional state field (select
) which holds the IDs of the selected items and is passed to processTreeViewItems
on each re-render.