mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
Updates files outside of x-pack to be triple-licensed under Elastic License 2.0, AGPL 3.0, or SSPL 1.0. |
||
---|---|---|
.. | ||
src/unsaved_changes_prompt | ||
index.ts | ||
jest.config.js | ||
kibana.jsonc | ||
package.json | ||
README.md | ||
tsconfig.json |
@kbn/unsaved-changes-prompt
The useUnsavedChangesPrompt function is a custom React hook that prompts users with a confirmation dialog when they try to leave a page with unsaved changes. It blocks navigation and shows a dialog using the provided openConfirm function. If the user confirms, it navigates away; otherwise, it cancels the navigation, ensuring unsaved changes are not lost.
import { useUnsavedChangesPrompt } from '@kbn/unsaved-changes-prompt';
export const SampleForm = ({ servicesForUnsavedChangesPrompt }) => {
const { form } = useForm();
const isFormDirty = useFormIsModified({ form });
useUnsavedChangesPrompt({
hasUnsavedChanges: isFormDirty,
...servicesForUnsavedChangesPrompt,
});
return (
<>
<Form form={form}>
....
</Form>
</>
);
};