
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-easy-preload
Advanced tools
Attention
You can find new releases there
Custom react router switch with topbar for easy data preloading

"react": "^16.8.0 || ^17.0.0",
"react-dom": "^16.8.0 || ^17.0.0",
"react-router-dom": "^5.0.0"
npm install react-easy-preload
## or
yarn add react-easy-preload
In your router section change react-router-dom's Switch to PreloadingSwitch
import { PreloadingSwitch, Route } from "react-easy-preload";
<PreloadingSwitch>
<Route />
<Route />
...
</PreloadingSwitch>
Add preload prop to every route that must be loaded before switching
<PreloadingSwitch>
//data will be loaded before switching
<Route preload />
//instant switch as before
<Route />
...
</PreloadingSwitch>
Add loadingContext.done() at the end of your initial loading method in pages that uses in routes you marked with preload prop
import { LoadingContext } from "react-easy-preload";
const loadingContext = useContext(LoadingContext);
const loading = async () => {
//loading some data
//call method to indicate that loading is done and we are ready to switch
loadingContext.done();
};
or for class components
import { LoadingContext } from "react-easy-preload";
class ClassComponent extends React.Component {
...
loading = async () => {
//loading some data
//call method from props to indicate that loading is done
this.props.loadingContext.done();
};
...
};
//we should wrap class component with Context Provider to get access to loading methods
const ClassComponentWrapper = (props) =>
<LoadingContext.Consumer>
{loadingContext => <ClassComponent loadingContext={loadingContext} {...props} />}
</LoadingContext.Consumer>
If you are using typescript to add preload prop to routes just import Route from this package instead of react-router-dom
import { PreloadingSwitch, Route } from "react-easy-preload";
<PreloadingSwitch>
//data will be loaded before switching
<Route preload />
//instant switch as before
<Route />
...
</PreloadingSwitch>
You can specify loading screen that would be shown at first loading of your app
const MyLoadingScreen = () => <div>Loading...</div>
<PreloadingSwitch loadingScreen={MyLoadingScreen}>
...
</PreloadingSwitch>
Call topbar.config() if you want to change topbar configuration. More info http://buunguyen.github.io/topbar/.
import { topbar } from "react-easy-preload";
topbar.config({
barColors: {
'0': 'rgba(26, 188, 156, .7)',
'.3': 'rgba(41, 128, 185, .7)',
'1.0': 'rgba(231, 76, 60, .7)'
},
shadowBlur: 0
});
Clone repository and run
yarn build && yarn example
FAQs
Custom react router switch !!! renamed to react-router-loading !!!
We found that react-easy-preload 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.