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.

Issue with className prop passing with Styled Components

See original GitHub issue

Thanks for a great project! Is there any insight into this warning I receive from styled-components when using it with Tippy React?

It looks like you've wrapped styled() around your React component (Popover), but the className prop is not being passed down to a child. No styles will be rendered unless className is composed within your React component.

Here is a codesandbox with the warning. Oddly enough, the example works as expected. I am wrapping the <Tippy /> component in a styled-component and that in turn styles the .tippy-tooltip element.

The warning is due to the fact I am passing in a custom component for content but my custom component is not receiving the props from styled-components (but I don’t need it to).

For now I’m just passing suppressClassNameWarning into StyledPopover (in my example).

Any thoughts would be great! Thanks again!

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
atomikscommented, May 12, 2019

Sorry for not checking this one earlier.

Edit: The supress warning is probably the only solution. https://github.com/styled-components/styled-components/issues/2159

I agree with this comment:

I’m really not happy with the need to add another prop just to suppress this warning, and I don’t really view deferred or relocated rendering as an ‘edge case’. I should be able to render the className later, or somewhere else, or not at all. Once the className is handed off, it’s not styled-components’s business how, if, or when I choose to use it.

I’ll just keep this issue open for now


If you don’t want to pass supressClassNameWarning every time, you can use this

import React from 'react';
import Tippy from '@tippy.js/react';
import styled from 'styled-components';

export default styled(({ suppressClassNameWarning, ...props }) => (
  <Tippy {...props} />
)).attrs({
  suppressClassNameWarning: true
})``;
1reaction
BrianMitchLcommented, Mar 22, 2019

Oh, of course, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Usage - styled-components
Passing a ref prop to a styled component will give you one of two things depending on the styled target: the underlying DOM...
Read more >
Can I pass a className as a prop to StyledComponent in ...
I've decided to style it using Styled-Components. In my React Application, I have three buttons with different actions and I would like them...
Read more >
How To Use Styled-Components In React - Smashing Magazine
Here, StyledButton is the styled component, and it will be rendered as an HTML button with the contained styles. styled is an internal...
Read more >
Complete Guide On How To Use Styled-components In React
You must pass in the className prop in the parent element of the component to be styled because with it styled component can...
Read more >
How To Use React Styled Components Efficiently - Copycat
Styled -components: Dynamic Styling with Props Passed ... thereby avoiding class name bugs and clashes, allowing use to build our apps ...
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