Files
5chan/src/components/ImageBanner.jsx
T

17 lines
472 B
React
Raw Normal View History

2023-02-08 21:49:36 +01:00
import React, { useState, useEffect } from 'react';
2023-03-03 14:44:34 +01:00
import { useLocation } from 'react-router-dom';
2023-02-08 21:49:36 +01:00
const ImageBanner = () => {
const [currentImage, setCurrentImage] = useState(1);
2023-03-03 14:44:34 +01:00
const location = useLocation();
2023-02-08 21:49:36 +01:00
useEffect(() => {
2023-02-27 17:44:02 +01:00
setCurrentImage(Math.floor(Math.random() * 13) + 1);
2023-03-03 14:44:34 +01:00
}, [location.key]);
2023-02-08 21:49:36 +01:00
return (
2023-03-03 15:06:04 +01:00
<img id="banner-img" src={`/assets/banners/banner-${currentImage}.jpg?${Date.now()}`} alt="banner" />
2023-02-08 21:49:36 +01:00
);
};
2023-03-03 15:06:04 +01:00
export default ImageBanner;