import type { BasePluginDependenciesAPI, EditorInjectionAPI, ExtractInjectionAPI, NextEditorPlugin } from '../types/next-editor-plugin'; type NamedPluginStatesFromInjectionAPI>, PluginNames extends string | number | symbol> = Readonly<{ [K in PluginNames as `${K extends string ? K : never}State`]: API[K] extends BasePluginDependenciesAPI | undefined ? ReturnType : never; }>; type ExtractPluginNames> = keyof API; type Cleanup = () => void; type Options = { disabled?: boolean; }; /** * * ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️ * If the plugins you are listening to generate multiple shared states while the user is typing, * your React Component will get only the last one. * * Used to run effects on changes in editor state - similar to `useSharedPluginState` except this * is for reacting to state changes so does not cause re-renders. The effect callback passed will be called * on initialisation and when the state changes (with the latest callback we are provided). * * Example in plugin: * * ```typescript * function ExampleContent({ api }: Props) { * const pluginStateCallback = useCallback(( { dogState, exampleState } ) => { * // Use as necessary ie. fire analytics or network requests * console.log(dogState, exampleState) * }, []) * usePluginStateEffect( * api, * ['dog', 'example'], * pluginStateCallback * ) * return

Content

* } * * const examplePlugin: NextEditorPlugin<'example', { dependencies: [typeof pluginDog] }> = ({ api }) => { * return { * name: 'example', * contentComponent: () => * * } * } * ``` * * @param injectionApi Plugin injection API from `NextEditorPlugin` * @param plugins Plugin names to get the shared plugin state for * @param effect A callback, the parameter is a corresponding object, the keys are names of the plugin with `State` appended, * the values are the shared state exposed by that plugin. This effect fires when the state changes and runs the most recent callback passed. * If the callback changes the effect is not re-run - it is still recommended however to wrap your effect in `useCallback`, * You can return a function from your effect to call any cleanup activities which will be called on unmount and when `editorApi` changes. */ export declare function usePluginStateEffect, PluginNames extends ExtractPluginNames>(injectionApi: API | null | undefined, plugins: PluginNames[], effect: (states: NamedPluginStatesFromInjectionAPI) => Cleanup | void, options?: Options): void; export {};