You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importaddonsfrom'@storybook/addons';import{addDecorator}from'@storybook/react';import{DARK_MODE_EVENT_NAME}from'storybook-dark-mode';// your theme providerimportThemeContextfrom'./theme';// get channel to listen to event emitterconstchannel=addons.getChannel();// create a component that listens for the DARK_MODE eventfunctionThemeWrapper(props){// this example uses hook but you can also use class component as wellconst[isDark,setDark]=useState(false);useEffect(()=>{// listen to DARK_MODE eventchannel.on(DARK_MODE_EVENT_NAME,setDark);return()=>channel.off(DARK_MODE_EVENT_NAME,setDark);},[channel,setDark]);// render your custom theme providerreturn(<ThemeContext.Providervalue={isDark ? darkTheme : defaultTheme}>{props.children}</ThemeContext.Provider>);}exportconstdecorators=[renderStory=><ThemeWrapper>{renderStory()}</ThemeWrapper>)]
It should be changed to:
import{useEffect}from'react';import{addons}from"@storybook/preview-api";import{DARK_MODE_EVENT_NAME}from'storybook-dark-mode';// your theme providerimportThemeContextfrom'./theme';// get channel to listen to event emitterconstchannel=addons.getChannel();// create a component that listens for the DARK_MODE eventfunctionThemeWrapper(props){// this example uses hook but you can also use class component as wellconst[isDark,setDark]=useState(false);useEffect(()=>{// listen to DARK_MODE eventchannel.on(DARK_MODE_EVENT_NAME,setDark);return()=>channel.off(DARK_MODE_EVENT_NAME,setDark);},[channel,setDark]);// render your custom theme providerreturn(<ThemeContext.Providervalue={isDark ? darkTheme : defaultTheme}>{props.children}</ThemeContext.Provider>);}exportconstdecorators=[renderStory=><ThemeWrapper>{renderStory()}</ThemeWrapper>)]
I've tested it to work correctly with Storybook 7.0.17. If you are interested, I can send a PR with a fix.
The text was updated successfully, but these errors were encountered:
It is now required to use new addons api in Storybook v7 – https://storybook.js.org/docs/react/addons/addons-api#addonsgetchannel
The events code won't work with Storybook 7.x:
It should be changed to:
I've tested it to work correctly with Storybook 7.0.17. If you are interested, I can send a PR with a fix.
The text was updated successfully, but these errors were encountered: