question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing theme explicitly in props

See original GitHub issue

Feature 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:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
probablyupcommented, Jun 9, 2019

This is out as of 4.3.x

0reactions
probablyupcommented, May 31, 2019

Maybe this weekend, there are a couple other pending PRs

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found