Skip to content

Commit

Permalink
Refactor, add back useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhabib committed May 10, 2024
1 parent 20a3990 commit ec8bad4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Playroom/Toolbar/Toolbar.tsx
@@ -1,4 +1,4 @@
import { useContext, useState, useCallback } from 'react';
import { useContext, useState, useCallback, useEffect } from 'react';
import { useTimeoutFn } from 'react-use';
import classnames from 'classnames';
import type { PlayroomProps } from '../Playroom';
Expand Down Expand Up @@ -64,6 +64,12 @@ export default ({ themes: allThemes, widths: allWidths, snippets }: Props) => {
const [lastActivePanel, setLastActivePanel] =
useState<typeof activeToolbarPanel>(undefined);

useEffect(() => {
if (activeToolbarPanel) {
setLastActivePanel(activeToolbarPanel);
}
}, [activeToolbarPanel]);

const hasSnippets = snippets && snippets.length > 0;
const hasFilteredFrames =
visibleThemes.length > 0 || visibleWidths.length > 0;
Expand Down Expand Up @@ -160,7 +166,6 @@ export default ({ themes: allThemes, widths: allWidths, snippets }: Props) => {
classNames={styles.transitionStyles}
mountOnEnter
unmountOnExit
onEnter={() => setLastActivePanel(activeToolbarPanel)}
onExited={() => setLastActivePanel(undefined)}
>
<div className={styles.panel} id="custom-id">
Expand Down

0 comments on commit ec8bad4

Please sign in to comment.