博客 / 詳情

返回

Styled Components: Enforcing Best Practices In Component-Based Systems

After this shift in mindset towards building component-based user interfaces, we are now in what we like to call the “component age.” The rise of JavaScript frameworks such as React, Ember and recently Angular 2, the effort of the W3C to standardize a web-native component system, pattern libraries and style guides being considered the “right way” to build web applications, and many other things have illuminated this revolution.

Styled Components - A screenshot of styled-components code

Best Practices In Component-Based Systems

As we’ve built more and more apps with components, we’ve discovered some best practices when working with them. I want to talk about three main ones today: building small, focused and independent components; splitting container and presentational components; and having single-use CSS class names.

Build-Small Components

Instead of relying on classes for composition, use components to your advantage and compose them together. For example, imagine a Button component that renders

user avatar
0 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.