-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from JollyGrin/feat/flip-enemycard
Feat/flip enemycard
- Loading branch information
Showing
9 changed files
with
307 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from "./useIsomorphicLayoutEffect"; | ||
export * from "./useEventCallback"; | ||
export * from "./useEventListener"; | ||
export * from "./useLocalStorage"; | ||
export * from "./useCopy"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useCallback, useRef } from "react"; | ||
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect"; | ||
|
||
export function useEventCallback<Args extends unknown[], R>( | ||
fn: (...args: Args) => R, | ||
): (...args: Args) => R; | ||
export function useEventCallback<Args extends unknown[], R>( | ||
fn: ((...args: Args) => R) | undefined, | ||
): ((...args: Args) => R) | undefined; | ||
export function useEventCallback<Args extends unknown[], R>( | ||
fn: ((...args: Args) => R) | undefined, | ||
): ((...args: Args) => R) | undefined { | ||
const ref = useRef<typeof fn>(() => { | ||
throw new Error("Cannot call an event handler while rendering."); | ||
}); | ||
|
||
useIsomorphicLayoutEffect(() => { | ||
ref.current = fn; | ||
}, [fn]); | ||
|
||
return useCallback((...args: Args) => ref.current?.(...args), [ref]) as ( | ||
...args: Args | ||
) => R; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { useEffect, useLayoutEffect } from "react"; | ||
|
||
export const useIsomorphicLayoutEffect = | ||
typeof window !== "undefined" ? useLayoutEffect : useEffect; |
Oops, something went wrong.