How to manage state in a tree component in reactjs

后端 未结 3 807
孤城傲影
孤城傲影 2021-02-02 14:37

I\'ve been struggling this for a couple of days, trying to figure out the \"react\" way to do it.

Basically, I have a tree, a list of lists (of lists ...) that can be ar

3条回答
  •  暖寄归人
    2021-02-02 15:25

    Seems like it'd be nicer to pass everything down as props, as this will prevent you from the trouble of managing individual insertion/deletion. Also, like the comments said, the key attributes prevents a huge chunk of unnecessary re-rendering.

    You might want to check this link: http://facebook.github.io/react/blog/2013/11/05/thinking-in-react.html. It describes the kind of dilemma you're having and how to approach it.

    (Coincidentally, I've made a react tree view a while ago: https://github.com/chenglou/react-treeview. Take whatever you want from it!)

提交回复
热议问题