use-axios-progress-bar
v1.0.2
Published
query progress react hook
Downloads
8
Maintainers
Readme
use-axios-progress-bar react hook
yarn add use-axios-progress-bar
ornpm i use-axios-progress-bar --save
- Find the progress bar component of your dream
- Use it
import useAxiosProgressBar from "use-axios-progress-bar";
const GlobalProgressBar = () => {
const currentProgress = useAxiosProgressBar();
/*
-1: no activity
0: smth is running, but exact loading/total ratio cannot be calculated
1-100: smth is running and loading/total ratio is known
*/
return (
<div>Current state: ${currentProgress}</div>
);
}
- Or something more usable and beautiful
import Axios from "axiosInstance";
import useAxiosProgressBar from "use-axios-progress-bar";
import LinearProgress from "@material-ui/core/LinearProgress";
import { css } from "@emotion/core";
/* Overprioriting MUI styles with && */
const fixedProgressBarCss = css`
&&{
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 10;
}
`;
const AxiosProgressIndicator = () => {
const loaded = useAxiosProgressBar({
axiosInstance: Axios,
delay: 500
});
return loaded === -1 ? null : (
<LinearProgress
css={fixedProgressBarCss}
value={loaded}
variant={loaded>0?"determinate":"indeterminate"}
/>
);
}
- Profit!