From 4520e6473afe901005e7ac532317f4b4f1af9ead Mon Sep 17 00:00:00 2001 From: fusagiko / takayamaki <24884114+takayamaki@users.noreply.github.com> Date: Mon, 3 Apr 2023 10:31:39 +0900 Subject: [Proposal] Make able to write React in Typescript (#16210) Co-authored-by: berlysia Co-authored-by: fusagiko / takayamaki --- app/javascript/hooks/useHovering.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/javascript/hooks/useHovering.ts (limited to 'app/javascript/hooks') diff --git a/app/javascript/hooks/useHovering.ts b/app/javascript/hooks/useHovering.ts new file mode 100644 index 000000000..2062e70d2 --- /dev/null +++ b/app/javascript/hooks/useHovering.ts @@ -0,0 +1,17 @@ +import { useCallback, useState } from 'react'; + +export const useHovering = (animate?: boolean) => { + const [hovering, setHovering] = useState(animate ?? false); + + const handleMouseEnter = useCallback(() => { + if (animate) return; + setHovering(true); + }, [animate]); + + const handleMouseLeave = useCallback(() => { + if (animate) return; + setHovering(false); + }, [animate]); + + return { hovering, handleMouseEnter, handleMouseLeave }; +}; -- cgit