Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function useRegisterStore( id, store ) {
const { registerStore } = useRegistry();
useConstructor( () => registerStore( id, store ) );
}
return ( props ) => {
const { setBlocks } = useDispatch( `wp-graphql-gutenberg/block-editor-preview` );
const registry = useRegistry();
const blocks = registry.select( `core/block-editor` ).getBlocks();
const coreBlock = useContext( CoreBlockContext );
const id = useSelect( ( select ) => select( `core/editor` ).getCurrentPostId(), [] );
const coreBlockId =
( coreBlock && coreBlock.attributes.ref && parseInt( coreBlock.attributes.ref, 10 ) ) || null;
useEffect( () => {
if ( id ) {
setBlocks( {
id,
blocks,
coreBlockId,
} );
}