From 2eef7225daf757fd97118f0a04b9eec52af5e1fd Mon Sep 17 00:00:00 2001 From: Kawa Date: Thu, 26 Mar 2026 10:24:32 +0100 Subject: [PATCH] feat(01-04): create WizardContext provider and wire into App - Create src/store/context.tsx: WizardContext, WizardProvider, useWizard hook - useWizard throws if used outside WizardProvider (prevents silent undefined state bugs) - Update src/App.tsx to wrap content in WizardProvider - npm run build exits 0 with no TypeScript errors --- src/App.tsx | 11 ++++++++--- src/store/context.tsx | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/store/context.tsx diff --git a/src/App.tsx b/src/App.tsx index 08e321e..4784599 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,12 @@ +// src/App.tsx +import { WizardProvider } from './store/context'; + export default function App() { return ( -
-

Ready2Blob

-
+ +
+

Ready2Blob

+
+
); } diff --git a/src/store/context.tsx b/src/store/context.tsx new file mode 100644 index 0000000..db27481 --- /dev/null +++ b/src/store/context.tsx @@ -0,0 +1,29 @@ +// src/store/context.tsx +// WizardContext, WizardProvider, and useWizard hook. +// useWizard throws if used outside WizardProvider — prevents silent "undefined state" bugs. + +import React, { createContext, useContext, useReducer } from 'react'; +import { WizardState, WizardAction, INITIAL_STATE } from './types'; +import { wizardReducer } from './reducer'; + +interface WizardContextValue { + state: WizardState; + dispatch: React.Dispatch; +} + +const WizardContext = createContext(null); + +export function WizardProvider({ children }: { children: React.ReactNode }) { + const [state, dispatch] = useReducer(wizardReducer, INITIAL_STATE); + return ( + + {children} + + ); +} + +export function useWizard(): WizardContextValue { + const ctx = useContext(WizardContext); + if (!ctx) throw new Error('useWizard must be used inside '); + return ctx; +}