Skip to content

Commit e61900a

Browse files
create-issue-branch[bot]magdalenajadachMagdalenaJadach
authored
Fix useEffect web component warnings (#674)
closes #668 --------- Co-authored-by: magdalenajadach <[email protected]> Co-authored-by: MagdalenaJadach <[email protected]>
1 parent 0b1e1e8 commit e61900a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## Unreleased
88

9+
### Fixed
10+
11+
- Fix useEffect missing dependencies (#674)
12+
913
### Changed
1014

1115
- Performance enhancements on app routes & sense hat transitions (#686)

src/components/WebComponentProject/WebComponentProject.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ const WebComponentProject = () => {
2424
? "dark"
2525
: "light";
2626
const isMobile = useMediaQuery({ query: MOBILE_MEDIA_QUERY });
27-
const [timeoutId, setTimeoutId] = React.useState(null);
2827
const webComponent = document.querySelector("editor-wc");
2928
const [codeHasRun, setCodeHasRun] = React.useState(false);
3029
const dispatch = useDispatch();
31-
dispatch(setIsSplitView(false));
30+
useEffect(() => {
31+
dispatch(setIsSplitView(false));
32+
}, [dispatch]);
3233

3334
useEffect(() => {
3435
setCodeHasRun(false);
35-
if (timeoutId) clearTimeout(timeoutId);
36-
const id = setTimeout(function () {
36+
const timeout = setTimeout(() => {
3737
const customEvent = new CustomEvent("codeChanged", {
3838
bubbles: true,
3939
cancelable: false,
4040
composed: true,
4141
});
4242
webComponent.dispatchEvent(customEvent);
4343
}, 2000);
44-
setTimeoutId(id);
45-
}, [project]);
44+
return () => clearTimeout(timeout);
45+
}, [project, webComponent]);
4646

4747
useEffect(() => {
4848
if (codeRunTriggered) {
@@ -69,7 +69,7 @@ const WebComponentProject = () => {
6969
});
7070
webComponent.dispatchEvent(runCompletedEvent);
7171
}
72-
}, [codeRunTriggered]);
72+
}, [codeRunTriggered, codeHasRun, webComponent]);
7373

7474
return (
7575
<>

0 commit comments

Comments
 (0)