"which function can I use to stop this back action" if you mean you are looking to stop the browser from completing its operation then that is not the way to design apps, useEffect with return statement is used for clean up work and not for mounting another component or showing messages
you can instead to use the onbeforeunload
event and clean up the handler on unmount
of the app, but it will show you a popup with default message that cannot be changed
useEffect(() => {
function showWarning() {
return '';
}
window.addEventListener('beforeunload', showWarning);
return () => {
window.removeEventListener('beforeunload', showWarning);
}
})