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.

Importing global style of styled-component for all stories

See original GitHub issue

This is not really a bug but I’m stuck importing global style of styled-component, for now I have to include it in every single of my story

import { storiesOf } from '@storybook/react'
import { withKnobs } from '@storybook/addon-knobs'

import MyComponent from '../components/MyComponent'
import { GlobalStyle } from '../pages/layout'

const stories = storiesOf('MyComponent', module)
stories.addDecorator(withKnobs)

stories.add(
  'My Component',
  () => (
    <>
      <GlobalStyle />
      <MyComponent />
    </>
  )
)

Issue Analytics

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

github_iconTop GitHub Comments

36reactions
tmeasdaycommented, Feb 14, 2019

Hi @eldyvoon,

The best approach here is to add a global decorator

// in config.js

import { addDecorator } from '@storybook/react';

addDecorator(s => <><GlobalStyle />{s()}</>);
32reactions
Sergioamjrcommented, Nov 29, 2020

With Storybook 6x I loaded my global style like this;

//.storybook/preview.js
import { addDecorator } from "@storybook/react";
import { GlobalStyle } from "./../pages/_app";

addDecorator((story) => (
  <>
    <GlobalStyle />
    {story()}
  </>
));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Default styles in Storybook with Styled Components
My global styles are created using styled-reboot, an addition to Styled ... import { createGlobalStyle } from "styled-components"; import ...
Read more >
Import Global Stylesheets for all Stories in preview.js
This is a great way to get general CSS into all stories and useful practice for adding resets, fonts, and globally shared stylesheets....
Read more >
Storybook: how to import styles for individual stories
My components are styled by the <style> block in the bottom of each .vue file. There are also some global CSS (Sass) files...
Read more >
6 Ways To Configure Global Styles for Storybook | by Jennifer Fu
We can verify that the global style changes have been applied to every story. However, the style change does not apply to any...
Read more >
Build UI components - Storybook Tutorials
+ import React from 'react'; + import { GlobalStyle } from '../src/shared/global'; /* * Global decorator to apply the styles to all stories...
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