Passing theme explicitly in props
See original GitHub issueFeature request
Similar to https://github.com/styled-components/styled-components/issues/294, I would like to be able to pass a theme directly to a styledComponent (overriding the one supplied by ThemeProvider if existent). Back then, this was fixed in https://github.com/styled-components/styled-components/commit/14c1c29deb7244129621a0333b2dc06b669f2f0d, but I suppose, this change was reverted by refactorings.
I imagine sth like:
{/* All children of this component will be red */}
<ThemeProvider theme={redTheme}>
<div>
<Button>I'm red!</Button>
<Button theme={yellowTheme}>I'm yellow!</Button>
</div>
</ThemeProvider>
This makes it easier to override the theme for single components and better testing. Are there any caveats for having this?
Thanks
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Is there a way to pass down props to a component implicitly?
I'd like to be able to set a global theme (set of variables) for all of my components ...
Read more >Passing Data Deeply with Context - React Docs
Passing props is a great way to explicitly pipe data through your UI tree to the components that use it. But passing props...
Read more >A better way of solving prop drilling in React apps
There are two ways of achieving this feat: By explicitly passing one or more component(s) to another component as that component's prop, which ......
Read more >Avoid Prop Drilling with React Context - Medium
This code is an example of prop drilling, as we need to explicitly pass the theme prop through every part of the component...
Read more >Parameter 'props' implicitly has 'any' type in React | bobbyhadz
We didn't have to set the children prop, but you would have to do that if you pass children to your component. If...
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
This is out as of 4.3.x
Maybe this weekend, there are a couple other pending PRs