fix(v2): do not focus on skip link if page refreshed (#4797)

* fix(v2): do not focus on skip link if page refreshed

* rename ref

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
Alexey Pyltsyn 2021-05-18 16:55:11 +03:00 committed by GitHub
parent ab19070ab5
commit 0360364570
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 9 deletions

View file

@ -0,0 +1,21 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {useRef, useEffect} from 'react';
import {useLocation} from '@docusaurus/router';
export function useChangeRoute(onRouteChange: () => void): void {
const {pathname} = useLocation();
const latestPathnameRef = useRef(pathname);
useEffect(() => {
if (pathname !== latestPathnameRef.current) {
latestPathnameRef.current = pathname;
onRouteChange();
}
}, [pathname, latestPathnameRef, onRouteChange]);
}