styled-components初探

386 阅读1分钟

在react开发中,可以使用使用CSS-in-JS,即styled-components

使用 yarn add --dev @types/styled-conponents

即可安装支持ts的styled-components,然后就可以在tsx文件里使用带标签的模板字符串啦

import styled from 'styled-components';

const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
`;

然后在return的html中直接使用即可

这样使用该标签就自带样式,可以复用,而且不用想className