Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
react-defer-until-interaction
Advanced tools
Delay loading and rendering until the user interacts with the page
Delay loading and rendering until the user interacts with the page
yarn add react-defer-until-interaction
# or
npm install react-defer-until-interaction
Wrap your component (or the whole app) in the provider:
import { DeferUntilInteractionProvider } from 'react-defer-until-interaction'
function App() {
return (
<DeferUntilInteractionProvider>
<MyContents />
</DeferUntilInteractionProvider>
)
}
In a Next.js app, add the provider to your _app.tsx
, and pass the NextRouter:
// _app.tsx
import { useRouter } from 'next/router'
import { DeferUntilInteractionProvider } from 'react-defer-until-interaction'
function App() {
const router = useRouter()
return (
<DeferUntilInteractionProvider router={router}>
<MyContents />
</DeferUntilInteractionProvider>
)
}
This will enable the module to re-run on each route change, as if the page was freshly loaded in the browser.
The hook will indicate that the user has interacted with the page, even if the user has not actually clicked/scrolled/etc, once 10 seconds have elapsed. This is meant as a safety fallback in case the events are somehow not heard, and for pages that are opened in the background (i.e. in a separate browser tab).
You may override the default timeout of 10 seconds by passing your own value (in milliseconds):
import { DeferUntilInteractionProvider } from 'react-defer-until-interaction'
function App() {
return (
<DeferUntilInteractionProvider timeout={5000} /* Assume that interaction has happened after 5 seconds */>
<MyContents />
</DeferUntilInteractionProvider>
)
}
You can also set timeout={0}
to disable the timer.
The useDeferUntilInteraction
hook exposes two properties, a boolean and a function.
hasInteracted
will be true after the user interacts with the page, or when 10 seconds have elapsedafterInteraction()
takes a callback and only invokes it after the user has interacted with the page, or when 10 seconds have elapsedimport { useDeferUntilInteraction } from 'react-defer-until-interaction'
function MyComponent() {
const { hasInteracted, afterInteraction } = useDeferUntilInteraction()
return (
<p>You {hasInteracted ? 'have' : 'have not'} interacted with the page.</p>
{afterInteraction(() => <BelowTheFold />)}
)
}
FAQs
Delay loading and rendering until the user interacts with the page
The npm package react-defer-until-interaction receives a total of 6 weekly downloads. As such, react-defer-until-interaction popularity was classified as not popular.
We found that react-defer-until-interaction 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.