mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-09 22:32:53 +02:00
refactor: cleanup scroll handlers (#5709)
This commit is contained in:
parent
c12fe963c9
commit
e22170408a
3 changed files with 77 additions and 92 deletions
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {useEffect, useRef} from 'react';
|
||||
import {useEffect} from 'react';
|
||||
import {useLocation} from '@docusaurus/router';
|
||||
import {Location} from '@docusaurus/history';
|
||||
import {usePrevious} from './usePrevious';
|
||||
|
@ -20,15 +20,8 @@ type OnLocationChange = (locationChangeEvent: LocationChangeEvent) => void;
|
|||
export function useLocationChange(onLocationChange: OnLocationChange): void {
|
||||
const location = useLocation();
|
||||
const previousLocation = usePrevious(location);
|
||||
const isFirst = useRef<boolean>(true);
|
||||
|
||||
useEffect(() => {
|
||||
// Prevent first effect to trigger the listener on mount
|
||||
if (isFirst.current) {
|
||||
isFirst.current = false;
|
||||
return;
|
||||
}
|
||||
|
||||
onLocationChange({
|
||||
location,
|
||||
previousLocation,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue