score:3

Accepted answer

You need to tell useEffect which variables to track, Change to

useEffect(() => {
    if (props.mode === 'view') {
        alert('Initializing in View Mode')
    } else {
        alert('NOT initializing in View Mode');
    }
}, [props.mode]);

(Note added by OP per responder's later comment: When React sees the same component on a new route, it will act as if merely the props have changed, but will not create a brand-new component that would have gone through useEffect(.., []) (initialization.)


Related Query

More Query from same tag