- Implement CameraFeed context and provider with reducer for state management
- able to switch footage on tab clicks
This commit is contained in:
16
src/app/context/CameraFeedContext.ts
Normal file
16
src/app/context/CameraFeedContext.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { createContext, useContext } from "react";
|
||||
import type { CameraFeedAction, CameraFeedState } from "../../types/types";
|
||||
|
||||
type CameraFeedContextType = {
|
||||
state: CameraFeedState;
|
||||
// check and refactor
|
||||
dispatch: (state: CameraFeedAction) => void;
|
||||
};
|
||||
|
||||
export const CameraFeedContext = createContext<CameraFeedContextType | null>(null);
|
||||
|
||||
export const useCameraFeedContext = () => {
|
||||
const ctx = useContext(CameraFeedContext);
|
||||
if (!ctx) throw new Error("useCameraFeedContext must be used inside <CameraFeedContext.Provider>");
|
||||
return ctx;
|
||||
};
|
||||
Reference in New Issue
Block a user