We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4988f92 commit c065ab1Copy full SHA for c065ab1
index.js
@@ -998,14 +998,16 @@ export function usePreferredLanguage() {
998
);
999
}
1000
1001
-export function usePrevious(newValue) {
1002
- const previousRef = React.useRef();
+export function usePrevious(value) {
+ const [current, setCurrent] = React.useState(value);
1003
+ const [previous, setPrevious] = React.useState(null);
1004
- React.useEffect(() => {
1005
- previousRef.current = newValue;
1006
- });
+ if (value !== current) {
+ setPrevious(current);
1007
+ setCurrent(value);
1008
+ }
1009
- return previousRef.current;
1010
+ return previous;
1011
1012
1013
export function useQueue(initialValue = []) {
0 commit comments