mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-24 22:46:57 +02:00
fix(v2): ignore hash changes in useChangeRoute hook (#5023)
* fix(v2): ignore hash changes in useChangeRoute hook * refactor and introduce useLocationChange hook Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
41eaa690ee
commit
8bda3b2dbf
8 changed files with 73 additions and 37 deletions
18
packages/docusaurus-theme-common/src/utils/usePrevious.ts
Normal file
18
packages/docusaurus-theme-common/src/utils/usePrevious.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* 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';
|
||||
|
||||
export function usePrevious<T>(value: T): T | undefined {
|
||||
const ref = useRef<T>();
|
||||
|
||||
useEffect(() => {
|
||||
ref.current = value;
|
||||
});
|
||||
|
||||
return ref.current;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue