gpt4 book ai didi

reactjs - Relay/Apollo 片段应该有多细粒度?

转载 作者:行者123 更新时间:2023-12-03 13:29:14 26 4
gpt4 key购买 nike

我在应用程序中使用 GraphQL + Relay,发现自己用 createFragmentContainer 包装了几乎所有组件,包括 DOM 层次结构中非常低的组件(通常是功能组件)。

这是使用片段的正确方法吗?我想知道何时将组件包装在片段容器中的准则是什么?当一个组件只需要一个字段并且我可以通过 props 从父级传递该数据时,包装该组件似乎是多余的。

我正在使用 Relay,但我认为这些概念也与 Apollo 类似。

最佳答案

这是我在 Relay 团队工作的同事 Jan Kassens 的回答:

If splitting out components makes sense to you, you should go for it. I find smaller modules generally help making code more understandable. Now, a Button component probably doesn't have to have a fragment attached to it, but if it's a "Like Page" button with a mutation and maybe label specific to the page, I think it makes total sense to make that it's own fragment container.

As with so many things in engineering, there's probably trade offs in splitting out too much, but we've spent a lot of thought on making fragment containers as lightweight and efficient as we can so you shouldn't think too hard about introducing overhead.

关于reactjs - Relay/Apollo 片段应该有多细粒度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53074038/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com