I have a Router defined on different paths using the same component, with the difference indicated via the mode prop.
<Route path="/viewAgreementForm">
<AgreementForm mode="view" />
</Route>
<Route path="/editAgreementForm">
<AgreementForm mode="edit" />
</Route>
The AgreementForm does some initialization in its useEffect(.., []).
Normally the routing works, but if I go from the View mode directly to the Edit mode, the re-initialization of the Edit-mode component doesn't work. So this section doesn't execute during the button link that takes me from View->Edit, although it does work if I open these routes independently from another screen:
useEffect(() => {
if (props.mode === 'view') {
alert('Initializing in View Mode')
} else {
alert('NOT initializing in View Mode');
}
}, []);
Sequence:
- Open View mode; correctly get the View initialization
- Click the button in the View mode that's supposed to take me to Edit.
- I do get the Edit-mode version of the component correctly changed and re-rendered, but I do not get to the initialization of
useEffect(.., []), and no alerts at all.
My understanding is: the Router destroys/recreates components on any route, so I'm dealing with brand-new components, isn't that true?