UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

36 lines 1.42 kB
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import { useLayoutEffect, useState } from 'react'; import { usePreviousState } from '@atlaskit/editor-common/hooks'; import { createUniversalPreset } from '../create-editor/create-universal-preset'; import { shouldRecreatePreset } from '../create-editor/preset-utils'; export default function useUniversalPreset(_ref) { var props = _ref.props, initialPluginConfiguration = _ref.initialPluginConfiguration; var previousEditorProps = usePreviousState(props); var _useState = useState(function () { return createUniversalPreset({ props: props, prevProps: previousEditorProps, initialPluginConfiguration: initialPluginConfiguration }); }), _useState2 = _slicedToArray(_useState, 2), preset = _useState2[0], setPreset = _useState2[1]; useLayoutEffect(function () { if (!previousEditorProps) { return; } var recreate = shouldRecreatePreset(previousEditorProps, props); if (!recreate) { return; } // we are not comparing the previous initialPluginConfiguration to the new one assuming that it never changes setPreset(createUniversalPreset({ props: props, prevProps: previousEditorProps, initialPluginConfiguration: initialPluginConfiguration })); }, [props, previousEditorProps, initialPluginConfiguration]); return preset; }