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.

[Request] Optional invariant violation when `theme` not found in props

See original GitHub issue

Background

First off, great job with the library! We use styled-components for our internal component library and as a result, a lot of end users of our library don’t know the implementation details of our components (and nor should they). The problem, however, is that because almost all components use the theme prop, not including the ThemeProvider at the top level of the application results in errors that appear like “Cannot find colors.primary of undefined”. This isn’t super clear to users who aren’t familiar with how our library is structured (or that it even uses styled-components under the hood) and results in a lot of confused Slack messages.

Request / Idea

Similar to how react-router-dom handles it (i.e. Error: Invariant failed: You should not use <Route> outside a <Router>), it would be great if there was a way to enable invariant violations when the theme prop is not found. Ideally, the error message itself would be customizable since in our case, we don’t use the ThemeProvider component directly but as part of another component.

If there is any interest in adding a feature like this, I could get a PR going. Lmk!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
probablyupcommented, Dec 6, 2019

@phucanhapril we removed the message in a later patch release

1reaction
probablyupcommented, Jun 11, 2019

Hmm ok, let me think about this some more

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - Child Components have no props.theme for Styled ...
This means that your 'normal' components won't get the theme-object in their props. It took me sometime to get that. They could have...
Read more >
Provider | React Redux
Invariant Violation. Could not find "store" in the context of "Connect(MyComponent)". Either wrap the root component in a <Provider> ...
Read more >
invariant violation viewproptypes has been removed from ...
The correct fix here is to switch to deprecated-react-native-prop-types or a type system like Typescript. Open side panel. React Native: Error upgrading to...
Read more >
MSBuild reference for .NET SDK projects - Microsoft Learn
Reference for the MSBuild properties and items that are understood by the .NET SDK.
Read more >
processUpdates when using jQuery Datatable plugin-Reactjs
Coding example for the question ReactJS error : Invariant Violation: processUpdates when using jQuery Datatable plugin-Reactjs.
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