我正在尝试使用样式化组件,但出现以下错误-
TypeError: CustomElement.extend is not a function
代码:-
import React, { Component } from 'react';
import './App.css';
import styled from 'styled-components';
const CustomElement = styled.div`
color: green;
font-size: 30px;
`
const BlueElement = CustomElement.extend`
color: blue;
`
class App extends Component {
render() {
return (
<div>
<CustomElement>
div
</CustomElement>
<BlueElement>
div
</BlueElement>
</div>
);
}
}
export default App;
最佳答案
改变
const BlueElement = CustomElement.extend`
color: blue;
`
至
const BlueElement = styled(CustomElement)`
color: blue;
`