Components will lose their states when unmounted, if you want to keep these states, you can move the state to their parent component or use global store like redux/zustand. Or just change the display css property rather than unmount them.
display