There is no one-size-fits-all approach to styling React components, as the best practice depends on the project's needs and the team's preferences. However, there are some general guidelines to consider:
Inline styling can be useful for small, dynamic styles that depend on component state or props. However, it's generally recommended to avoid excessive inline styles, especially for large components, as they can lead to performance issues and make the code harder to read. In the video I said that the impact is not much and that is because you would normally use a library like styled-components that has cleaver ways to make the styles performant.
Using separate CSS files for components can be beneficial for several reasons:
CSS Modules offer a good balance between inline styles and separate CSS files. They provide scoped styles with the maintainability of CSS files and automatically generate unique class names, which is particularly useful for large React applications.
Styled Components, a popular CSS-in-JS library, allow you to write CSS code within your JavaScript files while keeping styles scoped to specific components. This approach can be particularly useful for creating reusable, styled React components.
Ultimately, the choice between styling inside the component or in a separate file depends on factors such as project size, team preferences, and specific requirements. A hybrid approach, using different methods where they are most appropriate, is often the most effective strategy.