Skip to content

Commit

Permalink
Fix useEffect web component warnings (#674)
Browse files Browse the repository at this point in the history
closes #668

---------

Co-authored-by: magdalenajadach <[email protected]>
Co-authored-by: MagdalenaJadach <[email protected]>
  • Loading branch information
3 people authored Oct 12, 2023
1 parent 0b1e1e8 commit e61900a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

### Fixed

- Fix useEffect missing dependencies (#674)

### Changed

- Performance enhancements on app routes & sense hat transitions (#686)
Expand Down
14 changes: 7 additions & 7 deletions src/components/WebComponentProject/WebComponentProject.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ const WebComponentProject = () => {
? "dark"
: "light";
const isMobile = useMediaQuery({ query: MOBILE_MEDIA_QUERY });
const [timeoutId, setTimeoutId] = React.useState(null);
const webComponent = document.querySelector("editor-wc");
const [codeHasRun, setCodeHasRun] = React.useState(false);
const dispatch = useDispatch();
dispatch(setIsSplitView(false));
useEffect(() => {
dispatch(setIsSplitView(false));
}, [dispatch]);

useEffect(() => {
setCodeHasRun(false);
if (timeoutId) clearTimeout(timeoutId);
const id = setTimeout(function () {
const timeout = setTimeout(() => {
const customEvent = new CustomEvent("codeChanged", {
bubbles: true,
cancelable: false,
composed: true,
});
webComponent.dispatchEvent(customEvent);
}, 2000);
setTimeoutId(id);
}, [project]);
return () => clearTimeout(timeout);
}, [project, webComponent]);

useEffect(() => {
if (codeRunTriggered) {
Expand All @@ -69,7 +69,7 @@ const WebComponentProject = () => {
});
webComponent.dispatchEvent(runCompletedEvent);
}
}, [codeRunTriggered]);
}, [codeRunTriggered, codeHasRun, webComponent]);

return (
<>
Expand Down

0 comments on commit e61900a

Please sign in to comment.