Move away from MutationObserver
See original GitHub issueIs your feature request related to a problem? Please describe. MutationObserver is outside of the React DOM removal process and so it feels weird. It’s not causing a problem apart from possibly browser support issues and the perf impact of using it.
Describe the solution you’d like
In https://github.com/react-hook-form/react-hook-form/issues/26 @bluebill1049 says he needs mutation observer to realise when the field has been removed. However, that doesn’t seem necessary. If passing a ref as a function, React calls that function with null
once the DOM element is removed. So thats the best way of detecting the removal of the DOM node.
I appreciate I could be missing something here though if theres more to it than that.
Describe alternatives you’ve considered N/A
Additional context N/A
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Yeah I think we can leave what we have for now…
Hi @bluebill1049 The suggestion is to simply check null in your ref function. React calls it with null when the reference is removed exactly for the same use-case you need. Is there an advantage to using an external observer? Happy to PR. It will highly likely give a performance boost over mutation observer.