@awsui/components-react
Version:
On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en
24 lines • 1.08 kB
JavaScript
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { useEffect } from 'react';
import { useStableCallback } from '@awsui/component-toolkit/internal';
import { fireNonCancelableEvent } from '../internal/events';
import { useDebounceCallback } from '../internal/hooks/use-debounce-callback';
export function useChangeEffect(editor, onChange, onDelayedChange) {
const debouncedChangeHandler = useDebounceCallback((detail) => {
fireNonCancelableEvent(onDelayedChange, detail);
}, 0);
const handleChange = useStableCallback(() => {
const changeDetail = { value: (editor === null || editor === void 0 ? void 0 : editor.getValue()) || '' };
fireNonCancelableEvent(onChange, changeDetail);
debouncedChangeHandler(changeDetail);
});
useEffect(() => {
if (!editor) {
return;
}
editor.on('change', handleChange);
return () => editor.off('change', handleChange);
}, [editor, handleChange]);
}
//# sourceMappingURL=listeners.js.map