How to use the @wordpress/core-data.__experimentalUseEntitySaving function in @wordpress/core-data

To help you get started, we’ve selected a few @wordpress/core-data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WordPress / gutenberg / packages / block-library / src / template-part / edit.js View on Github external
const initialBlocks = useMemo( () => {
		if ( status !== 'publish' ) {
			// Publish if still an auto-draft.
			setStatus( 'publish' );
		}
		if ( typeof content !== 'function' ) {
			const parsedContent = parse( content );
			return parsedContent.length ? parsedContent : undefined;
		}
	}, [] );
	const [ blocks = initialBlocks, setBlocks ] = useEntityProp(
		'postType',
		'wp_template_part',
		'blocks'
	);
	const [ isDirty, isSaving, save ] = __experimentalUseEntitySaving(
		'postType',
		'wp_template_part',
		saveProps
	);
	const saveContent = useCallback( () => {
		_setContent( content( { blocks } ) );
		save();
	}, [ content, blocks ] );
	const setContent = useCallback( () => {
		_setContent( ( { blocks: blocksForSerialization = [] } ) =>
			serializeBlocks( blocksForSerialization )
		);
	}, [] );
	return (
		<>
github WordPress / gutenberg / packages / block-library / src / site-description / edit.js View on Github external
function SiteDescriptionEdit( {
	attributes,
	backgroundColor,
	className,
	fontSize,
	insertDefaultBlock,
	setAttributes,
	setBackgroundColor,
	setFontSize,
	setTextColor,
	textColor,

} ) {
	const [ description, setDescription ] = useEntityProp( 'root', 'site', 'description' );
	const [ isDirty, isSaving, save ] = __experimentalUseEntitySaving(
		'root',
		'site',
		'description'
	);

	const { customFontSize, textAlign } = attributes;
	const actualFontSize = customFontSize || fontSize.size;

	const preventNewlines = ( event ) => {
		if ( event.keyCode === ENTER ) {
			event.preventDefault();
			insertDefaultBlock();
		}
	};

	return (
github WordPress / gutenberg / packages / block-library / src / post-title / edit.js View on Github external
export default function PostTitleEdit() {
	const [ title, setTitle ] = useEntityProp( 'postType', 'post', 'title' );
	const [ , setSlug ] = useEntityProp( 'postType', 'post', 'slug' );
	const [ isDirty, isSaving, save ] = __experimentalUseEntitySaving(
		'postType',
		'post',
		saveProps
	);
	return (
		<>
			<button title="" disabled="{">
				{ __( 'Update' ) }
			</button>

@wordpress/core-data

Access to and manipulation of core WordPress entities.

GPL-2.0-or-later
Latest version published 12 days ago

Package Health Score

95 / 100
Full package analysis