-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3253a19
commit 9cb2fd6
Showing
2 changed files
with
14 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { useMemo } from 'react'; | ||
import { useGameState } from '~/hooks/useGame'; | ||
import { Actions } from '~/types/game'; | ||
import { getEventData } from '~/utils/getEventData'; | ||
|
||
export function useEventData<A extends keyof Actions>(action: A): Actions[A] | null { | ||
const state = useGameState(); | ||
return useMemo(() => { | ||
if (state.action !== action || state.extra === undefined) return null; | ||
return state.extra as Actions[A]; | ||
}, [action, state]); | ||
return useMemo( | ||
() => getEventData(action, state), | ||
[action, state], | ||
); | ||
} |
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,9 @@ | ||
import { Actions, GameStateExpanded } from '~/types/game'; | ||
|
||
export function getEventData<A extends keyof Actions>( | ||
action: A, | ||
state: GameStateExpanded, | ||
): Actions[A] | null { | ||
if (state.action !== action || state.extra === undefined) return null; | ||
return state.extra as Actions[A]; | ||
} |