1

I want to override a external module cssclass locally for a component

In my code

import `style` from './style.module.css' // this is local css module 
import `ExternalComponent` from 'ExternalComponent' // suppose this is external module i'm using 

    function Component(){
        return(
               <ExternalComponent/>
             )
    }

Now the ExternalComponent render a div element with a class parent. So if i am importing the ExternalComponent how can i override the parent class of ExternalComponent in my locally imported style module so that the style in the ExternalComponent change only for this component only and else where i'm using it does not change.

I'm using react by the way.

1 Answer 1

1

style.module.css

.whatever-name-scope {
  :global {
    .parent {
      // override here
    }
  }
}

Then your jsx goes:

function Component(){
  return (<div className={style.whateverNameScope}>
    <ExternalComponent/>
  </div>)
}
Sign up to request clarification or add additional context in comments.

3 Comments

What does global refer to
That syntax of style.module.css you showed is showing error
maybe we are using different flavor of css module syntax. That :global is telling the css module to un-suffix the css classname ".parent". Without it, css module system by default output sth like ".parent-2a8fb". I'm not sure which flavor you use, check the doc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.