Skip to content

Recursive deep tree #1718

Answered by EmilTholin
PiotrSnelewski asked this question in Q&A
May 12, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @PiotrSnelewski!

Your MST stores looks reasonable! You must also make sure that TreeItem is made into an observer right away, so that the recursive uses of the component are observers as well and not just the exported one.

import { observer } from "mobx-react-lite";
import React from "react";

const TreeItem = observer((props) => {
  const handleClick = () => {
    props.item.active ? props.item.deactivate() : props.item.activate();
  };

  return (
    <React.Fragment>
      <li onClick={handleClick}>{props.item.id}</li>
      {props.item.active && (
        <ul>
          {Array.from(props.item.children.values()).map((child) => (
            <TreeItem key={child.id} item={child} />

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@PiotrSnelewski
Comment options

Answer selected by PiotrSnelewski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants