// RookSyncGateContext.tsx import { createContext, useContext, type Dispatch } from 'react'; import type { RookSyncGateState, Action } from './RookSyncGateTypes'; /* This line of code is creating a context using the `createContext` function provided by React. The context being created is named `RookSyncGateContext` and it is defined to hold an object with two properties: `state` of type `RookSyncGateState` and `dispatch` of type `Dispatch`. The `Dispatch` type is a generic type that represents a function to dispatch actions. */ export const RookSyncGateContext = createContext< { state: RookSyncGateState; dispatch: Dispatch } | undefined >(undefined); /** * The function `useRookSyncGateContext` ensures that it is used within the `RookSyncGateProvider` * context. * @returns The `useRookSyncGateContext` custom hook is returning the context obtained from the * `RookSyncGateContext` using the `useContext` hook. If the context is not found, it throws an error * indicating that `useRookSyncGateContext` should be used inside `RookSyncGateProvider`. */ export const useRookSyncGateContext = () => { const context = useContext(RookSyncGateContext); if (!context) { throw new Error( 'useRookSyncGateContext should be used inside RookSyncGateProvider' ); } return context; };