synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
30 lines • 1.55 kB
TypeScript
import { PropsWithChildren } from 'react';
type GlobalIsEditingContextType = {
/** If true, the user is editing a resource and should be presented with a warning before navigating away or performing
* some other action that will destroy the unsaved changes */
isEditing: boolean;
/** Function to set the editing state. This should be called when the user starts or stops editing a resource */
setIsEditing: (value: boolean) => void;
};
type UnsubscribeFn = () => void;
type SubscribeFn = (callback: () => void) => UnsubscribeFn;
export type IsEditingStore = {
subscribe: SubscribeFn;
getSnapshot: () => boolean;
setIsEditing: (value: boolean) => void;
};
type GlobalIsEditingContextProviderProps = PropsWithChildren<IsEditingStore>;
/**
* Provider for context that tracks whether the user is currently editing a resource, to be used to prevent the user from
* navigating away before changes are saved.
*
* This context provider does not itself implement the logic to prevent navigation, but provides an interface for
* synchronizing with the editing state tracked in the application.
*/
export declare function GlobalIsEditingContextProvider(props: GlobalIsEditingContextProviderProps): import("react/jsx-runtime").JSX.Element;
/**
* Hook to access the global editing context so the application can prevent navigation away from a page if a resource is being edited.
*/
export declare function useGlobalIsEditingContext(): GlobalIsEditingContextType;
export {};
//# sourceMappingURL=GlobalIsEditingContext.d.ts.map