From 153f2187bd872eecef55c09b204fa32fa2405f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Go=C5=82=C4=85b?= Date: Thu, 25 Apr 2024 09:38:01 +0200 Subject: [PATCH 1/2] fix: use useState hook from storybook preview api --- src/index.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 8bdfda14..2913543c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,5 +1,4 @@ -import React from 'react'; -import { addons } from '@storybook/preview-api'; +import { addons, useState } from '@storybook/preview-api'; import { DARK_MODE_EVENT_NAME } from './constants'; import { store } from './Tool'; @@ -7,7 +6,7 @@ import { store } from './Tool'; * Returns the current state of storybook's dark-mode */ export function useDarkMode(): boolean { - const [isDark, setIsDark] = React.useState(store().current === 'dark'); + const [isDark, setIsDark] = useState(store().current === 'dark'); React.useEffect(() => { const chan = addons.getChannel(); From 7342b98dd10ca913ce1f17b9e651cae9d506c2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Go=C5=82=C4=85b?= Date: Thu, 25 Apr 2024 09:57:17 +0200 Subject: [PATCH 2/2] fix: use the useEffect from storybook preview api --- src/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 2913543c..6178cd58 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,4 +1,4 @@ -import { addons, useState } from '@storybook/preview-api'; +import { addons, useState, useEffect } from '@storybook/preview-api'; import { DARK_MODE_EVENT_NAME } from './constants'; import { store } from './Tool'; @@ -8,7 +8,7 @@ import { store } from './Tool'; export function useDarkMode(): boolean { const [isDark, setIsDark] = useState(store().current === 'dark'); - React.useEffect(() => { + useEffect(() => { const chan = addons.getChannel(); chan.on(DARK_MODE_EVENT_NAME, setIsDark); return () => chan.off(DARK_MODE_EVENT_NAME, setIsDark);