Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

reactjs - Styled components default styles fallback if no theme provided

I have created a design system in my monorepo using styled components & react. Currently if I import any component from the design system into any of the other packages in order for it to work successfully it needs to be inside a ThemeProvider with the required theme.

I am trying to have a set of default fallback styles if the components are rendered outside of a theme provider

export const ButtonStyled = styled.button`
    background: ${props => props.theme.button.colors.primary || '#f8f8f8'};
`

If I render this button outside of a theme provider I get Cannot read property 'colors' of undefined

question from:https://stackoverflow.com/questions/65644114/styled-components-default-styles-fallback-if-no-theme-provided

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...