diff --git a/src/components/TourGuideContext.ts b/src/components/TourGuideContext.ts index 4d92c1ef..e414a0c6 100644 --- a/src/components/TourGuideContext.ts +++ b/src/components/TourGuideContext.ts @@ -9,7 +9,7 @@ export interface Emitter { } export type Ctx = Record & { _default: T } -export type ITourGuideContext = { +export interface ITourGuideContext { setTourKey?: (tourKey: string) => void eventEmitter?: Ctx canStart: Ctx diff --git a/src/hooks/useTourGuideController.tsx b/src/hooks/useTourGuideController.tsx index 19879320..d6db52d1 100644 --- a/src/hooks/useTourGuideController.tsx +++ b/src/hooks/useTourGuideController.tsx @@ -10,10 +10,12 @@ export const useTourGuideController = (tourKey?: string) => { const { start, canStart, stop, eventEmitter, getCurrentStep, setTourKey } = React.useContext(TourGuideContext) - let key = tourKey ?? '_default' + const key = tourKey ?? '_default' const _start = (fromStep?: number) => { - setTourKey && setTourKey(key) + if (setTourKey) { + setTourKey(key) + } if (start) { start(key, fromStep) } @@ -33,7 +35,9 @@ export const useTourGuideController = (tourKey?: string) => { } React.useEffect(() => { - setTourKey && setTourKey(key) + if (setTourKey) { + setTourKey(key) + } }, []) const KeyedTourGuideZone: React.FC> =