@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
39 lines (38 loc) • 1.3 kB
JavaScript
import React from 'react';
function MountPluginHook({
usePluginHook,
editorView,
containerElement
}) {
usePluginHook({
editorView,
containerElement
});
return null;
}
export function MountPluginHooks({
pluginHooks,
editorView,
containerElement
}) {
if (!editorView) {
return null;
}
// Key each fiber by the plugin name carried on the hook function (set by
// `processPluginsList`). This keeps fibers stable across `reconfigureState`
// calls that change the plugin set — keying by array index would let React
// reuse the same fiber for a different `usePluginHook`, which calls a
// different sequence of hooks (Rules of Hooks violation).
// Falls back to the array index for any hook that wasn't annotated.
return /*#__PURE__*/React.createElement(React.Fragment, null, pluginHooks === null || pluginHooks === void 0 ? void 0 : pluginHooks.map((usePluginHook, index) => {
const pluginName = usePluginHook.pluginName;
return /*#__PURE__*/React.createElement(MountPluginHook
// eslint-disable-next-line react/no-array-index-key
, {
key: pluginName !== null && pluginName !== void 0 ? pluginName : index,
usePluginHook: usePluginHook,
editorView: editorView,
containerElement: containerElement
});
}));
}