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.

For some reason I thought this would work:

const Block = styled.div`
  background-color: blue;
  color: white;
`;

// Override Block and give it a red background, using all other styles (i.e. just adding another class that overrides the background-color
const EmergencyBlock = styled(Block)`
  background-color: red;
`;

Can we make this work? That would be a great overriding mechanism.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:24 (15 by maintainers)

github_iconTop GitHub Comments

17reactions
mxstbrcommented, Nov 22, 2016

You need to attach the class:

function Block(props){
 return <div className={props.className}></div>
}

styled-components injects a class with the given styling. If you don’t attach it to a DOM node, you’re not attaching it a DOM node, so it can’t be in the DOM!

3reactions
davibecommented, Nov 23, 2016

would it be possible pass the desired className to the styled function ? Maybe this is more a feature request. i.e.

const MyComponent = () => <div className="my-component"> ... </div>
module.exports = styled(component, {className: 'my-component'})`
    ...
`

I don’t like that my component has to behave (attach the custom className) as styled wants it to. I think the component should be agnostic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overriding in Java - GeeksforGeeks
In any object-oriented programming language, Overriding is a feature that allows a subclass or child class to provide a specific ...
Read more >
Overriding Definition & Meaning - Merriam-Webster
The meaning of OVERRIDING is chief, principal. How to use overriding in a sentence.
Read more >
Java - Overriding - Tutorialspoint
In object-oriented terms, overriding means to override the functionality of an existing method. Example. Let us look at an example. Live Demo. class...
Read more >
Method Overriding in Java - javatpoint
If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java. In...
Read more >
Overriding and Hiding Methods (The Java™ Tutorials ...
The ability of a subclass to override a method allows a class to inherit from a superclass whose behavior is "close enough" and...
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