I am trying to display a component <Top />
above another component <Bottom />
in React.
The code structure is as follows:
...
[top, setTop] = useState(false);
[bottom, setBottom] = useState(true);
...
return (
<div>
top && (<Top />)
bottom && (<Bottom />)
<button onClick = { () => setTop(true) } />
</div>
)
The issue I am facing is that when the user clicks the button to render <Top />
while seeing <Bottom />
, there is an "instant scrolling" effect that changes the viewport position to <Top />
.
Is there a way to render the component without changing the current viewport position?
Should I consider using CSS or javascript techniques to achieve this?