Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Table render twice on first mount (#34106)
* fix: Table render twice * chore: clean up * test: Fix test case
- Loading branch information
Showing
5 changed files
with
33 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useEffect, useRef } from 'react'; | ||
import useForceUpdate from '../../_util/hooks/useForceUpdate'; | ||
import ResponsiveObserve, { ScreenMap } from '../../_util/responsiveObserve'; | ||
|
||
function useBreakpoint(): ScreenMap { | ||
const [screens, setScreens] = useState<ScreenMap>({}); | ||
function useBreakpoint(refreshOnChange: boolean = true): ScreenMap { | ||
const screensRef = useRef<ScreenMap>({}); | ||
const forceUpdate = useForceUpdate(); | ||
|
||
useEffect(() => { | ||
const token = ResponsiveObserve.subscribe(supportScreens => { | ||
setScreens(supportScreens); | ||
screensRef.current = supportScreens; | ||
if (refreshOnChange) { | ||
forceUpdate(); | ||
} | ||
}); | ||
|
||
return () => ResponsiveObserve.unsubscribe(token); | ||
}, []); | ||
|
||
return screens; | ||
return screensRef.current; | ||
} | ||
|
||
export default useBreakpoint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.