Skip to content

Commit

Permalink
Merge pull request #279 from adam-golab/master
Browse files Browse the repository at this point in the history
Fix for the "Storybook preview hooks can only be called inside decorators and story functions." error
  • Loading branch information
hipstersmoothie committed Jun 19, 2024
2 parents efbd14a + 7342b98 commit 52fe0d9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React from 'react';
import { addons } from '@storybook/preview-api';
import { addons, useState, useEffect } from '@storybook/preview-api';
import { DARK_MODE_EVENT_NAME } from './constants';
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(() => {
useEffect(() => {
const chan = addons.getChannel();
chan.on(DARK_MODE_EVENT_NAME, setIsDark);
return () => chan.off(DARK_MODE_EVENT_NAME, setIsDark);
Expand Down

0 comments on commit 52fe0d9

Please sign in to comment.