The Building Your Own Hooks page suggests invoking the useEffect hook without passing in an empty dependency array
function useFriendStatus(friendID) {
const [isOnline, setIsOnline] = useState(null);
useEffect(() => {
function handleStatusChange(status) {
setIsOnline(status.isOnline);
}
ChatAPI.subscribeToFriendStatus(friendID, handleStatusChange);
return () => {
ChatAPI.unsubscribeFromFriendStatus(friendID, handleStatusChange);
};
});
return isOnline;
}
As there is no dependency array passed to useEffect, this would cause multiple multiple un/subscribe API calls. Shouldn't the example snippet have an empty dependency array?
The Building Your Own Hooks page suggests invoking the useEffect hook without passing in an empty dependency array
As there is no dependency array passed to useEffect, this would cause multiple multiple un/subscribe API calls. Shouldn't the example snippet have an empty dependency array?