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

Commit 477d360

Browse files
author
george
committed
Convert createRef to preferred useRef
1 parent 05d0270 commit 477d360

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

app/components/PageHeader/PageHeader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, { createRef, useState, useEffect } from "react"
1+
import React, { useRef, useState, useEffect } from "react"
22
import { withLastLocation } from "react-router-last-location"
33
import PropTypes from "prop-types"
44

55
import { FOCUSABLE_TABINDEX, UNFOCUSABLE_TABINDEX } from "./constants"
66

77
const PageHeader = props => {
88
const [tabIndex, setTabIndex] = useState(FOCUSABLE_TABINDEX)
9-
const headerRef = createRef()
9+
const headerRef = useRef(null)
1010

1111
useEffect(() => {
1212
if (props.lastLocation) {

app/layouts/Main/Main.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import "./styles.scss"
1414
import { FOCUSABLE_TABINDEX, UNFOCUSABLE_TABINDEX } from "./constants"
1515

1616
export default function Main() {
17+
const headerRef = React.useRef(null)
18+
const mainRef = React.useRef(null)
1719
const Attributes = {
1820
TABINDEX: "tabindex",
1921
}
22+
const getHeaderTabIndex = () => headerRef.current.getAttribute(Attributes.TABINDEX)
23+
const getMainTabIndex = () => mainRef.current.getAttribute(Attributes.TABINDEX)
2024

21-
const headerRef = React.createRef()
22-
const mainRef = React.createRef()
2325
const componentUnmountFunction = () => {
2426
ContextUtil.disableFocusOutline()
2527
}
@@ -34,9 +36,6 @@ export default function Main() {
3436
ref.current.focus()
3537
}
3638

37-
const getHeaderTabIndex = () => headerRef.current.getAttribute(Attributes.TABINDEX)
38-
const getMainTabIndex = () => mainRef.current.getAttribute(Attributes.TABINDEX)
39-
4039
const handleHeaderBlur = () => {
4140
if (getHeaderTabIndex() === UNFOCUSABLE_TABINDEX) return
4241
headerRef.current.removeAttribute(Attributes.TABINDEX)

0 commit comments

Comments
 (0)