Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
How to add global style option for a react UI library?

I need to add global styling option for my react component library. I have added global style as shown below

import { createGlobalStyle } from 'styled-components';

export const  GlobalStyle = createGlobalStyle`

  button{
    color: white;
    background-color: green;
  }
`;

and I have exported the component so that app consuming the my-ui-libray can use it

export * from './GlobalStyle.js'

And I have used the global style as following in a react app

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { GlobalStyle } from 'my-ui-libray';

const root = ReactDOM.createRoot(document.getElementById('root'));

root.render(
  <React.StrictMode>
    <GlobalStyle/>
      <App />
  </React.StrictMode>
);

The issue is the CSS Styles are not applied to the button in the react app which is using my library. Is there any issue in my above code? Or is there a better way to achieve the same?

Note:

Global style work when the component in used in react Storybook as shown in following code, but once I build and use the library in the react app it does not work.

const Template = (args) => <><GlobalStyle /><Button {...args} /></>;  

Reference: (Add global styles section)

https://storybook.js.org/tutorials/design-systems-for-developers/react/en/build/

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I find same issue on here enter link description here

you can try put your global style outside of strict mode

<GlobalStyle />
<React.StrictMode>
    <App />
</React.StrictMode>

or

<React.StrictMode>
    <NewComponent>
        <GlobalStyle />
        <App />
    </NewComponent>
</React.StrictMode>

my globalstyle can working in second solution

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!