CanopyTax / bandicoot

React rich text editor
https://bandicoot.js.org
MIT License
54 stars 2 forks source link

Switch to useLayoutEffect for dom operations #101

Closed joeldenning closed 3 years ago

joeldenning commented 3 years ago

cc @dvnrsn. This fixes a bug that I think was maybe caused by upgrading to React 17, where it says Cannot read property removeEventListener of undefined. I think the bug is caused by useEffect being cleaned up after dom operations are finished, which destroys the refs and dom elements stored in refs. By switching to useLayoutEffect, we clean up our event listeners before the ref and dom elements are destroyed.