Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita47e90d

Browse files
committed
debounce window resize
1 parentfe3125e commita47e90d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

‎web-app/src/components/Workspace/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import*asReactfrom'react'
22
import{css,jsx}from'@emotion/core'
3-
import{useWindowResize}from'../../services/hooks/resize'
3+
import{useWindowResize}from'./resize'
44

55
interfaceProps{
66
children:React.ReactElement

‎web-app/src/services/hooks/resize.tsrenamed to‎web-app/src/components/Workspace/resize.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ export const useWindowResize = () => {
1010

1111
// solution for windows getting off size
1212
React.useEffect(()=>{
13+
// timeoutId for debounce mechanism
14+
lettimeoutId:any
1315
consthandleResize=()=>{
14-
setDimensions(resize())
16+
if(timeoutId){
17+
// prevent execution of previous setTimeout
18+
clearTimeout(timeoutId)
19+
}
20+
timeoutId=setTimeout(()=>setDimensions(resize()),50)
1521
}
1622
window.addEventListener('resize',handleResize)
1723
return()=>window.removeEventListener('resize',handleResize)
18-
},[])
24+
},[window.innerWidth,window.innerHeight])
1925
returndimensions
2026
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp