type Node = {
id: string;
isExpanded: boolean;
children: Node[];
}
export function useTreeState() {
const [treeState, setTreeState] = createStore<Node[]>([]);
function setNodeExpansion(id: string, isExpanded: boolean): void {
setTreeState(
produce(tree => {
// Traverse down to get the node to update.
const foundNode = getNodeDeep(styleTree, id);
foundNode.isExpanded = true; // <---- this doesn't actually update
return tree;
}),
);
}
}
type Node = {
id: string;
isExpanded: boolean;
children: Node[];
}
export function useTreeState() {
const [treeState, setTreeState] = createStore<Node[]>([]);
function setNodeExpansion(id: string, isExpanded: boolean): void {
setTreeState(
produce(tree => {
// Traverse down to get the node to update.
const foundNode = getNodeDeep(styleTree, id);
foundNode.isExpanded = true; // <---- this doesn't actually update
return tree;
}),
);
}
}