xjpro / react-in-angularjs

A super simple way to render React components in AngularJS
The Unlicense
23 stars 13 forks source link

Сan i use useEffect clean-up function ? #14

Closed ZvozdaB closed 1 year ago

ZvozdaB commented 2 years ago

I try to use useEffect clean-up function or componentWillUnmount in angularize component but it not work. Work only in child component when angularize component exist and child component destroy. But if destroy angularize component clean-up function not work in angularize component or child component.

Сould you help? Thank you

xjpro commented 2 years ago

Could you post more code so I can see what's going on?

ornic commented 2 years ago

I do not know how to solve this problem in v17 React, but in v18 it solved by calling root.unmount() on React root while destroying AngularJS component/directive.

Please see:

ZvozdaB commented 1 year ago

@ornic thanks for your idea, here is a request on how to solve it for react 17. @xjpro can you merge it? This request will solve the problem of the accumulation of React components in the virtual DOM. This can be seen in the react-dev-tools tab components when going and returning to the page. Will also allow you to use useEffect clean-up function useEffect(() => { return () => { ...some code runs when component unmount } }, [])

https://github.com/xjpro/react-in-angularjs/pull/21

ZvozdaB commented 1 year ago

@xjpro almost all forks are used to raise the version of React to 18. Maybe it makes sense to make a major release by raising the version of React? and can use @ornic forks