styled-components 是一个流行的 CSS-in-JS 库, 它允许您在 JavaScript 中编写 CSS 样式,是 CSS-in-JS 方案中的一种实现方式。
styled-components is the result of wondering how we could enhance CSS for styling React component systems. By focusing on a single use case we managed to optimize the experience for developers as well as the output for end users.
如许就可以在底子样式组件上扩展其他样式,用来承接业务逻辑。
有些时候,我们想复用底子样式组件,但是 底子样式组件的 html 元素标签类型又不适用,这种情况可以利用 as 属性来动态更换底子样式组件的元素标签。
下面示例,是复用 StyledBaseButton 的样式,并将 button 标签更换为 a 标签。