Closed MateusLehmkuhl closed 4 years ago
Well, I agree with your statements, I had done it in the first instance in this second way that you suggested, (including in my first commit). Really, the ideal would be the two suggested implementations, I can go on working on that. You can then look at what I did on my first commit and then I revert my MR to him (https://github.com/stevage/mapbox-gl-utils/pull/12/commits/803f1b0f858eaa231617c9da34dcc70692957ef8).
I did it this way because it follows the React Hooks standards, e.g.:
useEffect (() => {
ChatAPI.subscribeToFriendStatus (friendID, handleStatusChange);
return () => {
ChatAPI.unsubscribeFromFriendStatus (friendID, handleStatusChange);
};
});
Thanks. After a bit more thought I think you're right - this way is better. I hadn't come across this pattern before.
In functions where is added a listener to map, added a function in return what i can use to disable this listeners.