Skip to content

Commit

Permalink
Merge pull request #21214 from storybookjs/20731-fix-unmounting-warning
Browse files Browse the repository at this point in the history
Docs: Remove warning when browsing away in React
  • Loading branch information
valentinpalkovic authored Mar 1, 2023
2 parents bd912fc + fae6632 commit a2c21df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions code/renderers/react/template/stories/teardown.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useEffect } from 'react';

const LoggingComponent = () => {
useEffect(() => {
console.log('mounted');
return () => {
console.log('unmounted');
};
}, []);

return 'Component';
};

export default {
component: LoggingComponent,
tags: ['autodocs'],
parameters: {
storyshots: { disable: true },
chromatic: { disable: true },
},
};

export const Default = {};
4 changes: 3 additions & 1 deletion code/ui/blocks/src/components/Story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ const InlineStory: FunctionComponent<InlineStoryProps> = (props) => {
);
setShowLoader(false);
return () => {
cleanup();
// It seems like you are supposed to unmount components outside of `useEffect`:
// https://github.com/facebook/react/issues/25675#issuecomment-1363957941
setTimeout(() => cleanup(), 0);
};
}, [autoplay, renderStoryToElement, story]);

Expand Down

0 comments on commit a2c21df

Please sign in to comment.