# post-carousel/4.0.8/src/hooks/useEditorSaveStatus.js

Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog &amp; News, version 4.0.8. 57 lines.

- Page: https://pluginprobe.com/plugins/post-carousel/4.0.8/code/src/hooks/useEditorSaveStatus.js
- Raw: https://pluginprobe.com/plugins/post-carousel/4.0.8/raw/src/hooks/useEditorSaveStatus.js
- Modified: 2026-09-02T10:51:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/post-carousel/4.0.8/code/src/hooks/useEditorSaveStatus.js#L10-L20`.

```javascript
import { useState, useEffect, useRef } from "@wordpress/element";
import { select, subscribe } from "@wordpress/data";

/**
 * useEditorSaveStatus
 *
 * Detects if *any* entity (post, page, template, widget, etc.)
 * is currently being saved — works in Site Editor, Post Editor, and Widgets.
 *
 * @return {Object} { isSaving, isAutosaving }
 */
export const useEditorSaveStatus = () => {
	const [isSaving, setIsSaving] = useState(false);
	const [isAutosaving, setIsAutosaving] = useState(false);
	const prevSavingRef = useRef(false);

	useEffect(() => {
		const unsubscribe = subscribe(() => {
			const core = select("core");
			if (!core) {
				return;
			}

			const { __experimentalGetDirtyEntityRecords, isSavingEntityRecord } = core;

			if (typeof __experimentalGetDirtyEntityRecords !== "function") {
				return;
			}

			const dirtyEntities = __experimentalGetDirtyEntityRecords();

			// Check if any entity is saving
			const isNowSaving = dirtyEntities.some((record) =>
				isSavingEntityRecord(record.kind, record.name, record.key)
			);

			// Detect autosaving from post editor if available
			const coreEditor = select("core/editor");
			const isNowAutosaving =
				typeof coreEditor?.isAutosavingPost === "function" ? coreEditor.isAutosavingPost() : false;

			// Update only when changed
			if (prevSavingRef.current !== isNowSaving) {
				setIsSaving(isNowSaving);
				prevSavingRef.current = isNowSaving;
			}
			setIsAutosaving(isNowAutosaving);
		});

		return () => {
			unsubscribe();
		};
	}, []);

	return { isSaving, isAutosaving };
};

```
