From 69914eea348c3406c3cae3be5c8a6e441c6d253d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Su=C3=A1rez?= Date: Thu, 7 Dec 2023 12:29:30 -0300 Subject: [PATCH] set initial blocks from the store --- .../src/components/iframe-editor/iframe-editor.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/js/product-editor/src/components/iframe-editor/iframe-editor.tsx b/packages/js/product-editor/src/components/iframe-editor/iframe-editor.tsx index 2e68d8b8215..435c159bbb5 100644 --- a/packages/js/product-editor/src/components/iframe-editor/iframe-editor.tsx +++ b/packages/js/product-editor/src/components/iframe-editor/iframe-editor.tsx @@ -43,7 +43,6 @@ type IframeEditorProps = { }; export function IframeEditor( { - initialBlocks = [], onChange = () => {}, onClose, onInput = () => {}, @@ -51,14 +50,23 @@ export function IframeEditor( { showBackButton = false, }: IframeEditorProps ) { const [ resizeObserver ] = useResizeObserver(); - const [ temporalBlocks, setTemporalBlocks ] = - useState< BlockInstance[] >( initialBlocks ); + const [ temporalBlocks, setTemporalBlocks ] = useState< BlockInstance[] >( + [] + ); // Pick the blocks from the store. const blocks: BlockInstance[] = useSelect( ( select ) => { return select( productEditorUiStore ).getModalEditorBlocks(); }, [] ); + /* + * Set the initial blocks from the store. + * @todo: probably we can get rid of the initialBlocks prop. + */ + useEffect( () => { + setTemporalBlocks( blocks ); + }, [] ); // eslint-disable-line + const { setModalEditorBlocks: setBlocks, setModalEditorContentHasChanged } = useDispatch( productEditorUiStore );