1
2
3
4
5
6
7
8
9
10
11
12
13
use dioxus::prelude::*;
use dioxus_native_core::NodeId;

use crate::TreeNode;

pub fn use_selected_node(node_id: &NodeId) -> Option<TreeNode> {
    let children = use_context::<Signal<Vec<TreeNode>>>();
    let children = children.read();

    let node = children.iter().find(|node| &node.id == node_id)?;

    Some(node.clone())
}