Skeleton
Skeleton is used to display the loading state of some component.
Import
import { Skeleton, SkeletonCircle, SkeletonText } from '@chakra-ui/react';
Usage
You can use it as a standalone component.
Or to wrap another component to take the same height and width.
Useful when fetching remote data.
import { Box } from '@chakra-ui/react';
function Card() {
const { data, loading, error } = useRemoteData();
if (error) return <Box children='error' />;
return (
<Box>
<Skeleton isLoaded={!loading}>
<Heading>{data.title}</Heading>
</Skeleton>
</Box>
);
}
Circle and Text Skeleton
Skeleton color
You can change the animation color with startColor
and endColor
.
Skipping the skeleton when content is loaded
You can prevent the skeleton from rendering using the isLoaded
prop.
fadeDuration
with isLoaded
With the fadeDuration
prop, you can control the duration of the content fading
into view. The value in this prop is a number representing seconds which is part
of the animation
style prop that is rendered to the component. Default value
is 0.4
seconds.
This requires the isLoaded
prop, and the animation is best visible when the
isLoaded
prop is toggled to true
.
Props
colorScheme
colorScheme
Color Schemes for Skeleton
are not implemented in the default theme. You can extend the theme to implement them.
string
endColor
endColor
The color at the animation end
string
fadeDuration
fadeDuration
The fadeIn duration in seconds. Requires isLoaded
toggled to true
in order to see the transition.
number
0.4
isLoaded
isLoaded
If true
, it'll render its children with a nice fade transition
boolean
size
size
Sizes for Skeleton
are not implemented in the default theme. You can extend the theme to implement them.
string
speed
speed
The animation speed in seconds
number
0.8
startColor
startColor
The color at the animation start
string
variant
variant
Variants for Skeleton
are not implemented in the default theme. You can extend the theme to implement them.
string