set initial blocks from the store

This commit is contained in:
Damián Suárez 2023-12-07 12:29:30 -03:00
parent c296776121
commit 69914eea34
1 changed files with 11 additions and 3 deletions

View File

@ -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 );