
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@gsts007/react-loading-context
Advanced tools
You can show your loading component anywhere.
And only one loading component is showing at the same time.
const App = () => {
return (
<LoadingContextProvider>
<LoadingContainer>
<MyLoadingLayer />
</LoadingContainer>
</LoadingContextProvider>
)
}
const SomeComponent = () => {
const { data, loading, error } = someAsyncAction();
useAutoLoading(loading);
...
};
yarn add @gsts007/react-loading-context
or
npm install --save @gsts007/react-loading-context
import { LoadingContextProvider } from '@gsts007/react-loading-context';
ReactDOM.render(
<React.StrictMode>
<LoadingContextProvider>
<App />
</LoadingContextProvider>
</React.StrictMode>,
document.getElementById('root'),
);
LoadingContainerLoadingContainer makes your loading component only shows when loading activated.
const App = () => {
return (
<>
...others
<LoadingContainer>
<MyLoadingComponent />
</LoadingContainer>
</>
);
}
useLoading hooksYou can get loading value using useLoading hooks.
const App = () => {
const loading = useLoading();
return (
<>
...others
{loading && <MyLoadingComponent>}
{/* or <MyLoadingComponent show={loading} /> */}
</>
);
};
LoadingConsumerIf you don't want to hooks, you can use LoadingConsumer.
const App = () => {
return (
<>
...others
<LoadingConsumer>
{loading => <MyLoadingComponent show={loading} />}
</LoadingConsumer>
</>
);
};
useLoadingActionYou can manually activate loading with useLoadingAction.
const { start, stop } = useLoadingAction();
useEffect(() => {
start();
const timer = setTimeout(() => {
stop();
}, 1000);
return () => {
clearTimeout(timer);
stop();
};
}, [start, stop]);
useAutoLoadingYou might have a loading variable if you use redux-thunk, apollo-client, or etc.
then, you can use useAutoLoading for activate and deactivate loading easily.
const { data, loading, error } = useQuery(...);
useAutoLoading(loading);
React Loading Context use loading counter system.
the loading action start means "increase the loading counter"
and also stop means "decrease the loading counter"
and we activate loading using whether loading counter is 0.
So, We shows loading component when any one loading in progress.
Get loading activation state
useLoading(): boolean
const loading = useLoading();
Automatically activate and deactivate loading using boolean parameter
useAutoLoading(loading: boolean): void
const { data, loading, error } = useSelector(state => state.asyncState);
useAutoLoading(loading);
Get actions for loading.
We recommend to use destructuring when use this hook.
useLoadingAction(): {
start: () => void;
stop: () => void;
};
const { start, stop } = useLoadingAction();
Show children when loading activated
LoadingComponent: React.FC
<LoadingComponent>
This text is showing when loading
</LoadingComponent>
LoadingConsumer: React.VFC<{ children: (loading: boolean) => React.ReactNode }>
<LoadingConsumer>
{loading => <Modal show={loading}>Loading...</Modal>}
</LoadingConsumer>
FAQs
React Loading Context
We found that @gsts007/react-loading-context demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.