mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-19 14:14:17 +00:00
refactor: expose actions through context
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { createContext, PropsWithChildren, useContext } from 'react';
|
||||
|
||||
import { useEntryActions } from '../../../common/hooks/useEntryAction';
|
||||
|
||||
type EntryActionsContextValue = ReturnType<typeof useEntryActions>;
|
||||
const RundownActionsContext = createContext<EntryActionsContextValue | null>(null);
|
||||
|
||||
interface RundownActionsProviderProps extends PropsWithChildren {
|
||||
actions: EntryActionsContextValue;
|
||||
}
|
||||
|
||||
export function RundownActionsProvider({ children, actions }: RundownActionsProviderProps) {
|
||||
return <RundownActionsContext.Provider value={actions}>{children}</RundownActionsContext.Provider>;
|
||||
}
|
||||
|
||||
export function useRundownEntryActions(): EntryActionsContextValue {
|
||||
const context = useContext(RundownActionsContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error('useRundownEntryActions must be used within RundownActionsProvider');
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
Reference in New Issue
Block a user