yardz commented on pull request #13497: URL: https://github.com/apache/superset/pull/13497#issuecomment-794293561
> * I think we can slightly increase the limit for breaking a component. Some components are very simple, non-reusable, and appear to be an internal part of the parent component. We don't want the original size of the component but also don't want to end up with labels or simple divs as separate components. A lot of fragmentation also doesn't help with readability. The key here is **balance**. I focus a lot on the principle of single responsibility. So I really like to break up components as much as possible so that the components are as simple as possible. 5 very simple components are easier to test and maintain than 1 complex component. Look at each component as if it were a function (after all, they are functions). What do you think of the same function with multiple "tasks" within its scope? In the same way that it is very strange to say that "this task is too small to be isolated in a function" I do not agree with "this is too small to be in its own component" About singletons: https://overreacted.io/writing-resilient-components/#principle-3-no-component-is-a-singleton (This article in general I think contains very good tips) > * Hooks are essentially **reusable** functions. You generally create them when you want to share stateful logic between components. Some of the hooks that you created are not reusable but internal functions of this component. I think they belong to the subcomponents that you created. Hooks are reusable functions, but they are not **essentially** reusable functions. Look this: https://reactjs.org/docs/hooks-intro.html#complex-components-become-hard-to-understand `Hooks let you split one component into smaller functions based on what pieces are related (such as setting up a subscription or fetching data)` Another function of hooks is to break the logic into smaller and related functions. Although the focus in these cases is not to be reusable. If the function is to be reused this is great, but it is not a "requirement" to create a hook (Certainly reuse is an excellent motivation, but it is certainly not the only one). Lastly. Always think on TDD, one of the advantages of using TDD is that you simply cannot make complex components, it is just too hard to do... ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
