@emotion/styled / styled-components创建带有样式的 React 组件

一、安装依赖

npm install @emotion/styled styled-components

二、使用

import styled from '@emotion/styled';
import styled from 'styled-components';

// 创建一个带样式的按钮
const StyledButton = styled.button`
  background-color: #4caf50;
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;

  &:hover {
    background-color: #45a049;
  }
`;

// 使用这个按钮
function App() {
  return 点击我;
}

export default App;

你可能感兴趣的:(react.js,前端,前端框架,javascript,ecmascript)