From e38b344cca977166b624d4b8f634ae25504ab657 Mon Sep 17 00:00:00 2001 From: Wes Rogers Date: Thu, 30 May 2024 22:37:45 -0700 Subject: [PATCH] Fixes findDOMNode errors for react 18 --- src/index.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index f83a11db..4d7705eb 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -3,8 +3,7 @@ React-Quill https://github.com/zenoamaro/react-quill */ -import React from 'react'; -import ReactDOM from 'react-dom'; +import React, { createRef } from 'react'; import isEqual from 'lodash/isEqual'; import Quill, { @@ -90,6 +89,7 @@ interface ReactQuillState { } class ReactQuill extends React.Component { + editingAreaRef = createRef() static displayName = 'React Quill' @@ -433,10 +433,10 @@ class ReactQuill extends React.Component { } getEditingArea(): Element { - if (!this.editingArea) { + if (!this.editingAreaRef.current) { throw new Error('Instantiating on missing editing area'); } - const element = ReactDOM.findDOMNode(this.editingArea); + const element = this.editingAreaRef.current; if (!element) { throw new Error('Cannot find element for editing area'); } @@ -455,9 +455,7 @@ class ReactQuill extends React.Component { const properties = { key: generation, - ref: (instance: React.ReactInstance | null) => { - this.editingArea = instance - }, + ref: this.editingAreaRef, }; if (React.Children.count(children)) {