Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 59123ca

Browse files
author
george
committed
update callbacks to use descriptive variables for useEffect hooks
1 parent 477d360 commit 59123ca

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

app/components/Article/Article.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ export default function Article(props) {
1414
COMPONENTS.forEach(Component => Component.stop())
1515
}
1616

17+
const onMountOnly = []
1718
useEffect(() => {
1819
Prism.highlightAll()
1920
COMPONENTS.forEach(Component => Component.start())
2021
setDomIsLoaded(true)
2122

2223
return componentUnmountFunction
23-
}, [])
24+
}, onMountOnly)
2425

2526
return (
2627
<article

app/components/PageHeader/PageHeader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import { FOCUSABLE_TABINDEX, UNFOCUSABLE_TABINDEX } from "./constants"
77
const PageHeader = props => {
88
const [tabIndex, setTabIndex] = useState(FOCUSABLE_TABINDEX)
99
const headerRef = useRef(null)
10+
const onMountOnly = []
1011

1112
useEffect(() => {
1213
if (props.lastLocation) {
1314
headerRef.current.focus()
1415
} else {
1516
setTabIndex(UNFOCUSABLE_TABINDEX)
1617
}
17-
}, [])
18+
}, onMountOnly)
1819

1920
const handleBlur = () => {
2021
if (tabIndex === UNFOCUSABLE_TABINDEX) return
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { useEffect } from "react"
22

33
export default function ScrollUpOnMount() {
4+
const onMountOnly = []
5+
46
useEffect(() => {
57
window.scrollTo(0, 0)
6-
}, [])
8+
}, onMountOnly)
79

810
return null
911
}

app/components/SideNav/SideNav.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,20 @@ export default function SideNav() {
3333
Accordions.stop()
3434
}
3535

36+
const onMountOnly = []
3637
useEffect(() => {
3738
Accordions.start()
3839
window.addEventListener("resize", handleMenuVisibility)
3940
setMenuIsOpen(isLargerThanCollapseWidth)
4041

4142
return componentUnmountFunction
42-
}, [])
43+
}, onMountOnly)
4344

45+
const updateConditions = [menuIsOpen]
4446
useEffect(() => {
4547
Accordions.stop()
4648
Accordions.start()
47-
}, [menuIsOpen])
49+
}, updateConditions)
4850

4951
// set up handlers and other helper methods
5052

app/layouts/Main/Main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ export default function Main() {
2626
ContextUtil.disableFocusOutline()
2727
}
2828

29+
const onMountOnly = []
2930
useEffect(() => {
3031
ContextUtil.enableFocusOutline()
3132
return componentUnmountFunction
32-
}, [])
33+
}, onMountOnly)
3334

3435
const handleRefocusClick = ref => {
3536
ref.current.setAttribute(Attributes.TABINDEX, FOCUSABLE_TABINDEX)

app/pages/Home/Home.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ export default function Home() {
4141
ANIMATION_DATA.forEach(instance => instance.animation.destroy())
4242
}
4343

44+
const onMountOnly = []
4445
useEffect(() => {
4546
Prism.highlightAll()
4647
loadAnimations()
4748

4849
return componentUnmountFunction
49-
}, [])
50+
}, onMountOnly)
5051

5152
const renderAnimations = () => {
5253
return ANIMATION_DATA.map(animation => {

0 commit comments

Comments
 (0)