TarVK / model-react

A data model system to use with react hooks
https://tarvk.github.io/model-react/examples/build/
MIT License
13 stars 3 forks source link

React possible memory leak warning #39

Closed TarVK closed 3 years ago

TarVK commented 3 years ago

I've noticed React complaining about invalid hook calls, and just realized the cause of this. I'm not properly cleaning up timeout on unmount: https://github.com/TarVK/model-react/blob/05a1efaafe1ac1153f99ae79cd084e7f434d559a/src/model/dataHooks/useDataHook.ts#L61

Simply adding a useEffect hook that clears the current timeout on unmount should fix this issue. It's worth considering whether we still want to trigger the onChange callback in that situation or not.