I am trying to build a simple page navigation loading screen while using react-router-dom. My first instinct to start is to do something like:
export default function PageOne = () => {
const [show, setShow] = useState('show');
useEffect(() => {
setTimeout(() => {
setShow('');
}, 500)
}, [])
return (
<>
<div className={`loader ${show}`}></div>
<div className="PageOne">
Here is my content for page one
</div>
</>
)
}
Here, the loader div would be displayed with a position: absolute, height: 100vh, and width: 100vw. Then after 500ms, it can be animated to fade out or slide off screen.
This doesn't feel like a great solution, and it means that the same code will be rewritten within every single page. Is there a simpler or more 'reacty' way to do this?