Styled Components does not allow me to set a background color
See original GitHub issueSo, just found out about Styled Components. I go on and yarn add it to my react native project, set it up and this happends:
Invariant Violation: Invalid prop `backgroundColor` supplied to `StyleSheet generated`: '#166191'
Valid color formats are
- '#f0f' (#rgb)
- '#f0fc' (#rgba)
- '#ff00ff' (#rrggbb)
- '#ff00ff00' (#rrggbbaa)
- 'rgb(255, 255, 255)'
- 'rgba(255, 255, 255, 1.0)'
- 'hsl(360, 100%, 100%)'
- 'hsla(360, 100%, 100%, 1.0)'
- 'transparent'
- 'red'
- 0xff00ff00 (0xrrggbbaa)
StyleSheet generated: {
"flexGrow": 1,
"flexShrink": 1,
"flexBasis": 0,
"backgroundColor": "'#166191'"
}
Here is my common.js file to group the few common styles in my app
import styled from 'styled-components/native';
export const Container = styled.View`
flex: 1;
background-color: '#166191';
`;
On my component I import the container through
import { Container } from '../styles/common';
and use it as <Container>
.
Why is this not working 😢
(moving all the code inside of the component file does not change anything)
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Styles are not working in through styled components
I am trying to add background-color through ...
Read more >How To Use React Styled Components Efficiently - Copycat
Learn how to set up organized React styled components in your project through examples, comprehensive explanations, and tips and tricks!
Read more >Styled Components in React and TypeScript | by Michael Gold
The div's background color is assigned a value according to the ... Now let's install styled-components so we can do the styling using...
Read more >Styled components, the styling library for your React apps you ...
We can simply install styled-components via NPM, like so: ... const Button = styled.button` background: black; color: white; border-radius: 7px; ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Leisors have you tried without quotes around the color value?
It finally worked, thanks!