import * as React from "react" ; export interface Tooltip2ContextState { forceDisabled ? : boolean ; } type Tooltip2Action = { type : "FORCE_DISABLED_STATE" ; } | { type : "RESET_DISABLED_STATE" ; } ; const noOpDispatch = ( ) => null ; export const Tooltip2Context = React . createContext < [ Tooltip2ContextState , React . Dispatch < Tooltip2Action > ] > ( [ { } , noOpDispatch , ] ) ; const tooltip2Reducer = ( state , action ) => { switch ( action . type ) { case "FORCE_DISABLED_STATE" : return { forceDisabled : true } ; case "RESET_DISABLED_STATE" : return { } ; default : return state ; } } ; interface Tooltip2ProviderProps { children : React . ReactNode | ( ( ctxState : Tooltip2ContextState ) => React . ReactNode ) ; forceDisable ? : boolean ; } export const Tooltip2Provider = ( { children , forceDisable } ) => { const [ state , dispatch ] = React . useReducer ( tooltip2Reducer , { } ) ; React . useEffect ( ( ) => { if ( forceDisable ) { dispatch ( { type : "FORCE_DISABLED_STATE" } ) ; } else { dispatch ( { type : "RESET_DISABLED_STATE" } ) ; } } , [ forceDisable ] ) ; return ( < Tooltip2Context . Provider value = { [ state , dispatch ] } > { typeof children === "function" ? children ( state ) : children } < /Tooltip2Context.Provider>); } ;