Skip to content

Commit

Permalink
fix(headless commerce): make parameter manager prop.initialState opti…
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeaudoincoveo authored Dec 6, 2024
1 parent d95ed0a commit 79433ed
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ParameterManagerProps<T extends Parameters> {
/**
* The initial state that should be applied to the `ParameterManager` sub-controller.
*/
initialState: ParameterManagerInitialState<T>;
initialState?: ParameterManagerInitialState<T>;
}

export interface CoreParameterManagerProps<T extends Parameters>
Expand Down Expand Up @@ -116,13 +116,15 @@ export function buildCoreParameterManager<T extends Parameters>(
const {dispatch} = engine;
const controller = buildController(engine);

validateInitialState(
engine,
initialStateSchema(props.parametersDefinition),
props.initialState,
'buildCoreParameterManager'
);
dispatch(props.restoreActionCreator(props.initialState.parameters));
if (props.initialState) {
validateInitialState(
engine,
initialStateSchema(props.parametersDefinition),
props.initialState,
'buildCoreParameterManager'
);
dispatch(props.restoreActionCreator(props.initialState?.parameters));
}

return {
...controller,
Expand Down

0 comments on commit 79433ed

Please sign in to comment.