Skip to content

Commit 2956d23

Browse files
authored
Return an unmount function from mountEditor (#53953)
1 parent a1da21c commit 2956d23

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
mountEditor() returns a function that unmounts the editor, so a host can clean up a comment form that closes.

‎projects/packages/comments/src/editor/index.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,17 @@ const Editor = ( {
237237
*
238238
* @param container - Where the editor renders.
239239
* @param props - Editor props.
240+
* @return A function that unmounts the editor, for a host whose form comes and goes.
240241
*/
241242
export const mountEditor = ( container: HTMLElement, props: EditorProps ) => {
242243
registerEmbedBlock( props.labels, props.previewEmbeds ?? true );
243244
registerImageBlock( props.labels, props.previewEmbeds ?? true );
244-
createRoot( container ).render(
245+
const root = createRoot( container );
246+
root.render(
245247
<Boundary onError={ props.onError }>
246248
<Editor { ...props } />
247249
</Boundary>
248250
);
251+
252+
return () => root.unmount();
249253
};

0 commit comments

Comments
 (0)