
Security News
Feross on Risky Business Weekly Podcast: npm’s Ongoing Supply Chain Attacks
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
react-loadable-visibility
Advanced tools
A wrapper around react-loadable for elements that are visible on the page
react-loadable-visibility
A wrapper around react-loadable and @loadable/component, only loading imports that are visible on the page.
react-loadable
import LoadableVisibility from "react-loadable-visibility/react-loadable";
import Loading from "./my-loading-component";
const LoadableComponent = LoadableVisibility({
loader: () => import("./my-component"),
loading: Loading
});
export default function App() {
return <LoadableComponent />;
}
@loadable/component
import loadableVisibility from "react-loadable-visibility/loadable-components";
import Loading from "./my-loading-component";
const LoadableComponent = loadableVisibility(() => import("./my-component"), {
fallback: <Loading />
});
export default function App() {
return <LoadableComponent />;
}
The API is exactly the same as the original library. Please refer to their documentation:
Note that you'll need to have react-loadable
or @loadable/component
in your package.json
.
It's in essence a wrapper around loadable
libraries with hooks into an IntersectionObserver
to inform us of when a given element is in the viewport.
Therefore, it will only function in browsers that have the IntersectionObserver
API.
A polyfill for IntersectionObserver
is available however I am skeptical of its performance but have not tested it fully to offer a recommendation here. If you have any comments about this, feel free to open a PR and adjust this README!
If you choose the use the polyfill, you can load it via a polyfill.io script - <script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver%2CIntersectionObserverEntry"></script>
Otherwise if the IntersectionObserver
API is not available, we will revert back to just using react-loadable
or @loadable/component
itself.
react-loadable
and @loadable/component
are fantastic higher level components to load additional modules once they are mounted on your page. It's great for keeping your bundle size small and pulling in a larger payload when the required components are part of your tree.
However it will not account for the content that's currently visible on your page, and only load what's actually visible to the end user. If you have a long page and are loading the entire content of that page for the user, even though they may only be able to see the content above the fold, it can be wasteful and especially detrimental in a mobile context.
react-loadable-visibility
is positioned to solve these issues by leveraging the existing awesome API of loadable
libraries with an extension to only trigger the loading of additional content once that component comes into view.
We'd like to thank the following people for their contributions:
Have a look at the GitHub contributors page for a full list of all contributors.
react-loadable-visibility
may be redistributed according to the BSD 3-Clause License.
Copyright 2019, Stratiform Limited.
FAQs
A wrapper around react-loadable for elements that are visible on the page
The npm package react-loadable-visibility receives a total of 2,306 weekly downloads. As such, react-loadable-visibility popularity was classified as popular.
We found that react-loadable-visibility 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 CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.