File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed
Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change 1- import React from 'react' ;
1+ import React , { useMemo , useState } from 'react' ;
22
33interface WizardFlowProps < Step extends keyof any > {
44 initialStep : Step ;
@@ -30,11 +30,22 @@ export function createWizardFlow<Steps extends Record<string, keyof any>>(
3030 DEFAULT_WIZARD_FLOW_CONTEXT ,
3131 ) ;
3232
33- const Provider = ( ) => {
34- /* hold context of what the current step is */
35- /* set context value for interacting with the flow state */
36- /* render provider and current step */
37- } ;
33+ function Provider ( { initialStep, onClose, steps } : WizardFlowProps < Step > ) {
34+ const [ step , setStep ] = useState < Step > ( initialStep ) ;
35+ const component = useMemo ( ( ) => steps [ step ] , [ steps , step ] ) ;
36+ const contextValue = useMemo (
37+ ( ) => ( {
38+ transition : ( step : Step ) : void => setStep ( step ) ,
39+ close : ( ) : void => {
40+ onClose && onClose ( ) ;
41+ } ,
42+ } ) ,
43+ [ onClose ] ,
44+ ) ;
45+ return (
46+ < Context . Provider value = { contextValue } > { component } </ Context . Provider >
47+ ) ;
48+ }
3849
3950 return { Provider, Context } ;
4051}
You can’t perform that action at this time.
0 commit comments