react redux: containers composition

后端 未结 2 1826
梦毁少年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.

    0 讨论(0)
  • 2021-02-08 03:55

    It's not easy to find which component should stay "dumb" and which component should be aware of application and become a container. I don't think it's a problem / anti-pattern to use a container in another one. If a part of your application is used on different pages it can be a container, be connected and use in differents pages/containers, Just be aware : this "container component" will specific to this application

    0 讨论(0)
提交回复
热议问题