gpt4 book ai didi

reactjs - 类型错误扩展不是样式组件中的函数

转载 作者:行者123 更新时间:2023-12-03 13:34:14 25 4
gpt4 key购买 nike

我正在尝试使用样式组件,但出现以下错误 -

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;
`

关于reactjs - 类型错误扩展不是样式组件中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52895599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com