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.

StyledComponent ThemeWrapper 0.91 -> 0.92

See original GitHub issue

Hey,

We’re using:

  • flow-typed: styled-components_v4.x.x.js (8ae4cfa383fc58443d8d65b5301bf1c1)
  • With the styleguide feature ThemeProvider wrapper

We’ve been using flow-bin v0.91.0, upgrading to either v0.92.0 or v0.93.0 results in a flood around use of theme, which had never appeared before.

export default () => (
      <ThemeProvider theme={OurTheme}>
        <Page />
      </ThemeProvider>
)

OurTheme contains things like breakpoint shortcuts that we use like this:

const PageWrapper = styled.div`
  margin-top: 6.8rem;
  @media ${({ theme }) => theme.breakpoint.onlyScreen.tablet} {
    margin-top: 7rem;
  };
  @media ${({ theme }) => theme.breakpoint.onlyScreen.laptop} {
    margin-top: 12rem;
  };
`;

This is giving us flow errors like this:

Cannot call styled.div because:                                                            
 • property theme is missing in object type [1] in the first argument of array element.    
 • property theme is missing in object type [1] in the first argument of array element.    
                                                                                           
     src/App/Component/Pages/Page.jsx                                                                        
     10│                                                                                   
     11│ const PageWrapper = styled.div`                                                   
     12│   margin-top: 6.8rem;                                                             
     13│   @media ${({ theme }) => theme.breakpoint.onlyScreen.tablet} {                   
     14│     margin-top: 7rem;                                                             
     15│   };                                                                              
     16│   @media ${({ theme }) => theme.breakpoint.onlyScreen.laptop} {                   
     17│     margin-top: 12rem;                                                            
     18│   };                                                                              
     19│ `;                                                                                
     20│                                                                                                                                       
                                                                                           
     flow-typed/npm/styled-components_v4.x.x.js
 [1]  9│                                     | (<P: {}>(executionContext: P) => string)
  • Anyone have any idea what would have changed to get flow bin to handle these differently in >0.92.0?
  • Is this styled-components flow-typed def presently able to handle themes?
  • If there’s a breaking change and I need to start providing a definition of my theme object, I have a Generic type ready to go, anyone have any idea where the best (and hopefully DRY-est) place is to declare this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
lukemartincommented, Feb 27, 2019

1reaction
jamesisaaccommented, Mar 3, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Usage - styled-components
styled -components has full theming support by exporting a <ThemeProvider> wrapper component. This component provides a theme to all React components ...
Read more >
styled-components-theme-provider - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
How to use Themes in styled-components - DEV Community ‍ ‍
jsx the component, we now import the theme component that was just created to wrap our entire function. By wrapping our App function,...
Read more >
styled-components-theme-connector - npm
Start using styled-components-theme-connector in your project by running ... Wrap root component with a default theme config: const theme ...
Read more >
Can't get Jest to work with Styled Components which ... - GitHub
Personally I provide default props to any styled component using the theme, e.g: const Wrapper = styled.div` color: ${props ...
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