
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
@invisionag/react-skeletons
Advanced tools
Hook to streamline loading animations in React components
react-skeletons consists of two components:
useSkeleton
hookThe hook can be used in components that control loading state as well as in components that display loading state. It automatically communicates loading state down the render tree via contexts. You tell the hook during initialization whether you want to set a new loading condition or just register a loading layout and then wrap the components return value in the hooks response (see Example)
Skeleton
componentThe component is straightforward. It's a div
element with a skeleton animation. It is built with styled components and extendable.
Props:
width
: Allows to set the css value for width directly as a propheight
: Allows to set the css value for height directly as a propimport React from 'react';
import { useSkeleton, Skeleton } from '@invisionag/react-skeletons';
const LoadableComponent = () => {
const [data, setData] = React.useState();
const [isLoading, setIsLoading] = React.useState(true);
const { withSkeleton } = useSkeleton({
isLoading,
Skeleton: () => <Skeleton width="200px" height="24px" />,
});
React.useEffect(() => {
fetch('example.com').then((data) => {
setData(data);
setIsLoading(false);
});
}, []);
return withSkeleton(<p>{data}</p>);
};
You can use the hook to control a loading state in a controlling component high up in the tree and then use the hook again in your "dumb" components just to register a skeleton layout. They will use the loading state in their closest parent.
import React from 'react';
import { useSkeleton, Skeleton } from '@invisionag/react-skeletons';
const App = () => {
const [data, setData] = React.useState();
const [isLoading, setIsLoading] = React.useState(true);
const { withSkeleton } = useSkeleton({
isLoading,
});
React.useEffect(() => {
fetch('example.com').then((data) => {
setData(data);
setIsLoading(false);
});
}, []);
return withSkeleton(
<div>
<Text>{data}</Text>
<Button>Save</Button>
</div>,
);
};
const Text = ({ children, ...rest }) => {
const { withSkeleton } = useSkeleton({
Skeleton: () => <Skeleton width="200px" height="24px" />,
});
return withSkeleton(<p {...rest}>{children}</p>);
};
const Button = ({ children, ...rest }) => {
const { withSkeleton } = useSkeleton({
Skeleton: () => <Skeleton width="120px" height="30px" />,
});
return withSkeleton(<button {...rest}>{children}</button>);
};
FAQs
Hook to streamline loading animations in React components
The npm package @invisionag/react-skeletons receives a total of 82 weekly downloads. As such, @invisionag/react-skeletons popularity was classified as not popular.
We found that @invisionag/react-skeletons demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 22 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.