added useRandomFeaturedWallpaperUrl hook

This commit is contained in:
SrGooglo 2024-02-19 18:58:16 +00:00
parent b45091ce6d
commit 997685dac9

View File

@ -0,0 +1,26 @@
import React from "react"
export default () => {
const [wallpaperData, setWallpaperData] = React.useState(null)
const setRandomWallpaper = async () => {
const { data: featuredWallpapers } = await app.cores.api.customRequest({
method: "GET",
url: "/featured_wallpapers"
}).catch((err) => {
console.error(err)
return []
})
// get random wallpaper from array
const randomWallpaper = featuredWallpapers[Math.floor(Math.random() * featuredWallpapers.length)]
setWallpaperData(randomWallpaper)
}
React.useEffect(() => {
setRandomWallpaper()
}, [])
return wallpaperData
}