Home > front end >  Call function when user leaves the page
Call function when user leaves the page

Time:11-14

Hi, I have button, that close the edit mode. That button use the 'editMode' function. I want to call it, when user navigate to any other page or update the page.

            <Box data-automation-id="button-fast-adding-close" onClick={editMode} sx={{ cursor: 'pointer' }}>
                <CloseIcon />
            </Box>

How can I use 'editMode' for the actions, that I described above?

CodePudding user response:

You can trigger the function when your component unmounts. With react hooks you can do it like this

useEffect(() => () => editMode(), []);
  • Related