Skip to content

Commit

Permalink
Sync store in edit component
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed May 23, 2024
1 parent 87c89b2 commit 64984f2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/block-editor/src/components/block-edit/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import {
getBlockType,
} from '@wordpress/blocks';
import { useContext, useMemo } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import BlockContext from '../block-context';
import { store as blockEditorStore } from '../../store';

/**
* Default value used for blocks which do not define their own context needs,
Expand Down Expand Up @@ -48,9 +50,14 @@ const Edit = ( props ) => {
const EditWithFilters = withFilters( 'editor.BlockEdit' )( Edit );

const EditWithGeneratedProps = ( props ) => {
const { attributes = {}, name } = props;
const { clientId, attributes = {}, name } = props;
const blockType = getBlockType( name );
const blockContext = useContext( BlockContext );
// Sync the block context with the block editor store.
useDispatch( blockEditorStore ).updateBlockContext(
clientId,
blockContext
);

// Assign context values using the block type's declared context needs.
const context = useMemo( () => {
Expand Down

0 comments on commit 64984f2

Please sign in to comment.