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.

Generic parameters not persisted through styled components

See original GitHub issue

Current behavior:

TypeScript generic parameters are not accessible through the styled wrapper.

To reproduce:

CodeSandbox example: https://codesandbox.io/s/sad-easley-bw821

  1. have a generic component with generic props
  2. wrap as a styled component
  3. generic parameter not accessible on the wrapped component

Expected behavior:

Generic parameter is accessible on the resulting HoC. Alternatively, I’m OK with using a type assertion here – I’m just not quite sure what I should be asserting as.

Environment information:

  • react version: 16.8
  • @emotion/react version: 10.0
  • @emotion/styled version: 10.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Andaristcommented, Apr 11, 2021

@tills13 you can extend your assertion with ComponentSelector: https://codesandbox.io/s/objective-mclaren-zv8cb?file=/src/App.tsx

0reactions
tills13commented, Apr 15, 2021

@Andarist this works for my use case. Thanks for the replies.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make Styled components generic to receive parameters?
I'm trying to use Styled Components with React FC. I want to display few details inside a div container, which all has the...
Read more >
Component prop types are not inferred when using styled ...
Component prop types are not inferred when using styled-components and TypeScript generic parameters. Expect to see someProp, instead no props are shown.
Read more >
Styled Components - Gatsby
In this guide, you will learn how to set up a site with the CSS-in-JS library Styled Components. Styled Components lets you use...
Read more >
Theming and Theme Switching with React and styled ...
Let's set up a project with React and styled-components. ... to a database so we can persist all the themes along with the...
Read more >
ASP.NET Core Blazor CSS isolation - Microsoft Learn
In the following example, the style is not applied to the child component. Pages/Parent.razor : razor. Copy.
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