diff options
author | crupest <crupest@outlook.com> | 2021-06-15 22:17:47 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-06-15 22:17:47 +0800 |
commit | d7a216295c2b4dcd7e931c38edd25e1b7ef7a395 (patch) | |
tree | 52f48b7ea15ba5e3a96298e51633292487e75795 /FrontEnd/src/utilities/useValueWithRef.ts | |
parent | c94784c9693648c2376d1aeaeae379ddc0036a32 (diff) | |
download | timeline-d7a216295c2b4dcd7e931c38edd25e1b7ef7a395.tar.gz timeline-d7a216295c2b4dcd7e931c38edd25e1b7ef7a395.tar.bz2 timeline-d7a216295c2b4dcd7e931c38edd25e1b7ef7a395.zip |
...
Diffstat (limited to 'FrontEnd/src/utilities/useValueWithRef.ts')
-rw-r--r-- | FrontEnd/src/utilities/useValueWithRef.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/FrontEnd/src/utilities/useValueWithRef.ts b/FrontEnd/src/utilities/useValueWithRef.ts new file mode 100644 index 00000000..8c5f2039 --- /dev/null +++ b/FrontEnd/src/utilities/useValueWithRef.ts @@ -0,0 +1,11 @@ +import React from "react"; + +export default function useValueWithRef<T>( + value: T +): React.MutableRefObject<T> { + const ref = React.useRef<T>(value); + React.useEffect(() => { + ref.current = value; + }, [value]); + return ref; +} |