react redux: containers composition

后端 未结 2 1828
梦毁少年i
梦毁少年i 2021-02-08 03:37

I am building an React+Redux application, I come to the point where I am considering to use a container inside another container. I am asking myself if this is a good approach,

2条回答
  •  走了就别回头了
    2021-02-08 03:53

    Let me quote Dan Abramov's article about presentational- and container- components:

    When you notice that some components don’t use the props they receive but merely forward them down and you have to rewire all those intermediate components any time the children need more data, it’s a good time to introduce some container components. This way you can get the data and the behavior props to the leaf components without burdening the unrelated components in the middle of the tree.

    ...meaning it is perfectly fine to have a container component inside another container component if you feel the need for it.

提交回复
热议问题