Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48978

IonPage: useEffect with history.listen

$
0
0

I am wondering if it’s safe to use history.listen inside a useEffect on an IonPage.

ex.

    useEffect(() => {
        return history.listen((location): void => {
            if (location.pathname === '/hello') {
                // do stuff 
            }
        });
    }, []);

My concern is that the returned function from listen() not being called and unregistering the listener. IonPage's (from my experience) don’t always unmount as expected and the above create multiple listeners every time this page was loaded/rendered.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48978

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>