LoginSignup
0
0

More than 3 years have passed since last update.

学んだこと 2021/03/week4

Posted at

TreeViewを開いたままにする対応


  const [expanded, setExpanded] = React.useState<string[]>([]);


  ...
       <TreeItem nodeId={child.nodeId}
                          onClick={() => {
                            setExpanded(["1"])
                            history.push(child.link)
                          }
                          }
                          icon={child.icon}
                          label={child.title}
                          classes={{
                            iconContainer: classes.icon,
                            root: classes.treeItem,
                            label: classes.label
                          }}
                />

単純だけどこんな感じでクリックした時に
useStateで
セットしてあげることで

初期表示時はclose
クリック後はopenを再現できる。

クリック後閉じたい場合は

setExpanded(["1"])
↓
setExpanded([])

にしてあげる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0