UseSelect in deprecated Migrate function ?
-
Hi Everyone,
I’m currently working on a block deprecation for a custom Block and I’m looking for a way to get the post title in the migrate function.
Previously, the block had ablockCustomTitle
(optional) and apageHeaderTitle
attribute which have been deleted in the new version, and replaced bycore/heading
andcore/paragraph
blocks.
When migrating the block from the old version to the new one, I would like to use the post title and pass it into a newcore/heading
.
Obviously,useSelect
does not working because it is asynchronous.
But I am then wondering if there is a way to get dynamic data when migrating a deprecated block (getting post informations, meta, etc…) ?migrate(attributes, innerBlocks) { const { blockCustomTitle, pageHeaderTitle,...restAttributes } = attributes; const pageTitle = useSelect((select) => { const { getEditedPostAttribute } = select("core/editor"); return getEditedPostAttribute("title"); }); return [ restAttributes, [ createBlock("homegrade-content-blocks/section-titling", { content: attributes.sectionTitle, level: 3, }, [ createBlock("core/heading", { placeholder: "Titre de section", content: attributes.hasCustomTitle ? blockCustomTitle : pageTitle, level: 1, className: "section_titling__title", }), createBlock("core/paragraph", { content: attributes.pageHeaderTitle, placeholder: "Tapez votre sous-titre...", className: "section_titling__subtitle", }), ], ), ...innerBlocks, ], ]; },
- The topic ‘UseSelect in deprecated Migrate function ?’ is closed to new replies.