I'm trying to use styled-components but get the below error -
TypeError: CustomElement.extend is not a function
Code:-
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;
Now you have your fonts, place them in your app, for example in a folder called src/fonts . Next create a global style using styled-components. We'll call this file fontStyles. js and place it in the src/ file of our React app.
One way to dynamically change css properties with styled components is to insert a custom prop into your React component and access said property using the dollar sign and curly braces commonly used for template literals. Our current example is testing to see if our use pointer prop is true.
shouldForwardProp ( (prop: string) => bool [optional]): Indicates whether the prop should be forwarded to the Component .
It Solves CSS Specificity Problems Styled components eliminate specificity problems as it encapsulates CSS inside a component. This means you don't have to worry about class names clashing or your UI turning into a mess due to class name clashes.
Change
const BlueElement = CustomElement.extend`
color: blue;
`
To
const BlueElement = styled(CustomElement)`
color: blue;
`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With