Skeleton Loading Images
Unanswered
Australian Freshwater Crocodile posted this in #help-forum
Australian Freshwater CrocodileOP
'use client'
import Image from 'next/image'
import Skeleton from 'react-loading-skeleton'
import 'react-loading-skeleton/dist/skeleton.css'
import { useState } from 'react'
export default function Home() {
const [ isLoaded, setIsLoaded ] = useState(false)
return (
<main className="bg-black h-screen">
<div className="absolute top-0 left-0 w-full h-full">
{!isLoaded && <Skeleton height={500} width={500} />}
<Image
src="https://api.daad.wtf/discord/user/1104076205105365064/avatar"
width={500}
height={500}
alt="Avatar"
onLoad={() => setIsLoaded(true)}
/>
</div>
</main>
)
}Is there a better way to do this - I notice that the image loads which goes underneath the skeleton, I onlywant to show the full image once it is loaded.
This is my first time using NextJS so sorry lol
5 Replies
Northern Wheatear
In my opinion the best way is to use placeholder prop in the Image component and set it to blur
Then you should specify blurDataURL which should be a base64 image of what you need to display while the image loads
In this case you can give the base64 url of a skeleton component or an image icon whichever suits best
Australian Freshwater CrocodileOP
I will look into that, thanks
Northern Wheatear
https://nextjs.org/docs/app/api-reference/components/image#placeholder
Read through this for more details
Read through this for more details