Skip to content

Commit 632bba8

Browse files
tested performance, no longer concerned, removing TODO
1 parent bf59292 commit 632bba8

File tree

1 file changed

+0
-14
lines changed

1 file changed

+0
-14
lines changed

src-ts/lib/hooks/use-check-is-mobile.hook.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@ import { Dispatch, SetStateAction, useEffect, useState } from 'react'
22

33
import { Breakpoints } from '../styles'
44

5-
/**
6-
* TODO: Refactor
7-
* There is risk of a performance hit if we make this a hook and call it in multiple components,
8-
* as it will re-render down the tree, change state at each instance of this hook call, and start
9-
* another re-render at that component and below. the resize event is also called constantly as a
10-
* window size is dragged, so this could get really janky in the some browsers.
11-
* Two recommendations to avoid that:
12-
* 1. call this once, put the result in state fairly close to the root of the component tree, and use that value
13-
* throughout all lower level components.
14-
* 2. debounce the event listener - it doesn't look like we're debouncing anything in the app yet, but we do import lodash,
15-
* which has a debounce function. I'd recommend calling the handler once every 100ms - slow enough that the browser doesn't churn,
16-
* but quick enough that most people won't notice.
17-
*/
18-
195
function checkIsMobile(): boolean {
206
return window.innerWidth <= Breakpoints.mdMax
217
}

0 commit comments

Comments
 (0)