I am trying to detect a user pressing the back button. I have a component that logs POP every time, even when the user did not press back button. I want to run this code only when the user navigated to the component from another screen. How do I do this?
const history = useHistory();
useEffect(() => {
    console.log(history.action)
    if (history.action == 'POP') {
        // process
}, [data])
 
    