registerBlockType with apiFetch
-
Hi there.
I use wp 6.6, clean database, no any plugins, sage theme by roots.
I have a lot of custom blocks (not acf). Currently i would like to have one js for all my blocks.
For example this is working as well:const blocks = [
'faq',
'login-form',
];
blocks.forEach(block => {
const name =gutengood/${block}
;
registerBlockType(name, {
title: block,
icon: 'block-default',
category: 'common',
edit: (props) => {
return (
<Fragment>
<InspectorControls>
<BlockOptions name={name} props={props}/>
</InspectorControls>
<ServerSideRender
block={name}
attributes={props.attributes}
/>
</Fragment>
)
},
save: () => null,
});
});But when i’m getting the same list of blocks using rest api sometimes blocks are not initialized in the editor after edit page reload, although they are in the page code. Also i see them in dropdown (plus button). Is it possible to fix display in the editor after reloading the edit page?
apiFetch({path: '/gutengood/v1/blocks'})
.then((blocks) => {
blocks.forEach(block => {
const name =gutengood/${block}
;
registerBlockType(name, {
title: block,
icon: 'block-default',
category: 'common',
edit: (props) => {
return (
<Fragment>
<InspectorControls>
<BlockOptions name={name} props={props}/>
</InspectorControls>
<ServerSideRender
block={name}
attributes={props.attributes}
/>
</Fragment>
)
},
save: (props) => null,
});
});
})
.catch((error) => console.error(error?.message));
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.