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
This commit is contained in:
2026-03-26 10:24:32 +01:00
parent 3fade79ea1
commit 2eef7225da
2 changed files with 37 additions and 3 deletions
+8 -3
View File
@@ -1,7 +1,12 @@
// src/App.tsx
import { WizardProvider } from './store/context';
export default function App() { export default function App() {
return ( return (
<div className="p-4"> <WizardProvider>
<h1 className="text-2xl font-bold">Ready2Blob</h1> <div className="p-4">
</div> <h1 className="text-2xl font-bold">Ready2Blob</h1>
</div>
</WizardProvider>
); );
} }
+29
View File
@@ -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<WizardAction>;
}
const WizardContext = createContext<WizardContextValue | null>(null);
export function WizardProvider({ children }: { children: React.ReactNode }) {
const [state, dispatch] = useReducer(wizardReducer, INITIAL_STATE);
return (
<WizardContext.Provider value={{ state, dispatch }}>
{children}
</WizardContext.Provider>
);
}
export function useWizard(): WizardContextValue {
const ctx = useContext(WizardContext);
if (!ctx) throw new Error('useWizard must be used inside <WizardProvider>');
return ctx;
}