That’s quite correct, the return part is the problem, because returning from useEffect means that whatever code you return runs only when the component unmounts. So, removing the return keyword should fix it.
I don’t think you can use it in a component like that, history will be undefined.
Create the Router/Switch/Route in App and then use the hook in one of the route components. Also, just to be clear, history.listen returns an cleanup function you can use inside useEffect for the cleanup (to unlisten).
What exactly are you trying to do inside the history listener? You might also look at the useLocation hook.
I basicly want to create a Analytics function so everytime it goes to a new url (using Link) i want a function to run so i can use fetch and send that data to the back-end so it can put it in the database.
But If anyone has a better idea please let me know
The docs have an example of the useLocation hook with google analytics.
You can create a custom hook as shown and use that in the App component. Although, I do find the docs on both hooks fairly lacking. Not really sure what the rules are for using them but with this hook it seems the App component has to be inside the Router.