Skip to content

Commit

Permalink
fix: useEffect ran twice in StrictMode
Browse files Browse the repository at this point in the history
refs: #14
  • Loading branch information
maraisr committed Sep 20, 2022
1 parent ad55c6f commit 3b9fda6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/Tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ export const Tools = () => {

// Avoid some "getting ready" states
useEffect(() => {
api.once(STORY_RENDERED, () => void setReady(true));
}, []);
const handler = () => {
api.off(STORY_RENDERED, handler); // api.once doesnt work in strict mode here
setReady(true);
};

api.on(STORY_RENDERED, handler);

return () => api.off(STORY_RENDERED, handler);
}, [api]);

const disabled =
typeof parameters.disable === 'boolean' ? parameters.disable : false;
Expand Down

0 comments on commit 3b9fda6

Please sign in to comment.