Styled-components theme not working
See original GitHub issueFor some reason, my rebass components are not detecting the theme I’m providing it. The weirdest thing is that through styled-components, the theme works well.
Main Theme:
const fontSizes: any = [
"12px",
"13px",
"14px",
"16px",
"18px",
"20px",
"24px",
"32px"
];
fontSizes.tiny = fontSizes[0];
fontSizes.small = fontSizes[1];
fontSizes.body = fontSizes[2];
fontSizes.body2 = fontSizes[3];
fontSizes.big = fontSizes[5];
fontSizes.display = fontSizes[6];
const space: any = [
0,
'5px',
'10px',
'15px',
'20px',
'25px',
'30px',
'35px',
'40px',
'45px',
'65px',
'80px'
];
space.tiny = space[1];
space.small = space[3];
space.medium = space[4];
space.big = space[6];
space.huge = space[8];
export default {
fontSizes,
space,
colors: {
text: '',
background: 'white',
primary: 'red',
gray: '#dfdfdf',
},
breakpoints: ["38em", "62em", "68em", "110em"],
};
SideBar
import styled, { ThemeProvider } from 'styled-components';
import MenuItem from './MenuItem';
import { Box } from 'rebass';
import main from '../../../themes/main';
const SidebarContainer = styled.div`
background-color: ${props => props.theme.colors.background};
grid-row: sidebar-start / sidebar-end;
grid-column: sidebar-start / sidebar-end;
/* padding: ${props => props.theme.space.small}; */
`;
const SideBar: React.FC = () => {
return (
<SidebarContainer>
<ThemeProvider theme={main}>
<Box px="2" backgroundColor="primary">
<MenuItem>My Questions</MenuItem>
</Box>
</ThemeProvider>
</SidebarContainer>
);
};
export default SideBar;
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Not able to access theme in styled component using ...
I'm using @emotion/react to theming and injected theme into it, I'm able to access theme using useTheme into component but not able to...
Read more >Advanced Usage - styled-components
This component provides a theme to all React components underneath itself via the context API. In the render tree all styled-components will have...
Read more >Empty theme context for 'external' components #2379 - GitHub
I have exact same problem, theme is in the context for all the internal components, but in external components theme is not defined....
Read more >How to use Themes in styled-components - DEV Community
First things first, import React from the react dependency, and then we import ThemeProvider from the styled-components file. Theme provider ...
Read more >Adding themes to a React app using styled-components | Blog
Adding themes to a React app using styled-components ... Now that we're using a theme in our application, it is not much extra...
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 FreeTop 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
Top GitHub Comments
If you’re using the latest Rebass, you’ll need to import from
rebass/styled-components
if you’re using the styled-components libraryGreat! The motivation is fairly similar to the motivation in Theme UI here: https://theme-ui.com/motivation/ but Emotion has an API to clean up props from the HTML output, which Styled Components does not have