🐛(fix) fix body scroll when a modal is opened
It was possible to scroll the body when a modal is opened, it was cutting the visibility of the modal, and was simply weird. Fixes #263
This commit is contained in:
19
packages/react/src/hooks/usePrevious.ts
Normal file
19
packages/react/src/hooks/usePrevious.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
/**
|
||||
* Hook which stores the previous value of a component prop or state.
|
||||
* https://usehooks.com/usePrevious/
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
const usePrevious = <T>(value: T): T => {
|
||||
const previous = useRef<T>(value);
|
||||
|
||||
useEffect(() => {
|
||||
previous.current = value;
|
||||
}, [value]);
|
||||
|
||||
return previous.current;
|
||||
};
|
||||
|
||||
export default usePrevious;
|
||||
Reference in New Issue
Block a user