Hacker News new | ask | show | jobs
by davnicwil 3996 days ago
> Except that there are use cases where you want to use boilerplate HTML in more than one component

In this case, you can split out that boilerplate into a separate, smaller component and reuse it inside as many other components as you need.

> By that logic we should be putting our data stores in the component, any translations required to internationalize the component, the database queries.

I respectfully disagree with your inference here - such functions can be abstracted and used by many components - in most cases there's no value in baking them directly into a component.

The exception to this is if the function is not abstract at all, makes no sense outside the context of the component, and therefore can't be reused. Then, it probably makes more sense to put it inside the component, rather than breaking it out into a separate file.

This is true of most if not all of the markup and styles used inside a component, which is why React encourages JSX and inline styles to be put directly inside the component as it's the only place they make sense, and the only place they'll be used. The markup, styles and component behaviour are intrinsically coupled, there is a lot of 1:1 referencing, and separating them out into separate files means you'll just be flicking between three files when working on a component, instead of one. Where there is 1:n referencing, well, that's when you should break your component into smaller, reusable pieces.