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; +}