
Research
/Security News
Popular Tinycolor npm Package Compromised in Supply Chain Attack Affecting 40+ Packages
Malicious update to @ctrl/tinycolor on npm is part of a supply-chain attack hitting 40+ packages across maintainers
@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'),
);
LoadingContainer
LoadingContainer
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} /> */}
</>
);
};
LoadingConsumer
If you don't want to hooks, you can use LoadingConsumer
.
const App = () => {
return (
<>
...others
<LoadingConsumer>
{loading => <MyLoadingComponent show={loading} />}
</LoadingConsumer>
</>
);
};
useLoadingAction
You can manually activate loading with useLoadingAction
.
const { start, stop } = useLoadingAction();
useEffect(() => {
start();
const timer = setTimeout(() => {
stop();
}, 1000);
return () => {
clearTimeout(timer);
stop();
};
}, [start, stop]);
useAutoLoading
You 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.
Research
/Security News
Malicious update to @ctrl/tinycolor on npm is part of a supply-chain attack hitting 40+ packages across maintainers
Security News
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.