Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@better-hooks/window
Advanced tools
Handle window events and observe window size
🔮 Simple usage
🚀 Fast and light
✨ Lifecycle Window events
💎 Lifecycle Document events
🎯 Window size
🪄 Window scroll position
💡 Window focus
🎊 SSR Support
npm install --save @better-hooks/window
or
yarn add @better-hooks/window
import React from "react";
import { useWindowEvent } from "@better-hooks/window";
const MyComponent: React.FC = () => {
// Unmounts event with component lifecycle
useWindowEvent("scroll", () => {
// ... Do something
});
useWindowEvent("wheel", () => {
// ... Do something
});
useWindowEvent("resize", () => {
// ... Do something
});
return (
// ...
)
}
import React from "react";
import { useDocumentEvent } from "@better-hooks/window";
const MyComponent: React.FC = () => {
// Unmounts event with component lifecycle
useDocumentEvent("visibilitychange", () => {
// ... Do something
});
useDocumentEvent("scroll", () => {
// ... Do something
});
return (
// ...
)
}
import React from "react";
import { useWindowSize } from "@better-hooks/window";
const MyComponent: React.FC = () => {
// Updates with resizing
const [width, height] = useWindowSize()
return (
// ...
)
}
import React from "react";
import { useWindowScroll } from "@better-hooks/window";
const MyComponent: React.FC = () => {
// Updates when scrolling
const [x, y] = useWindowScroll()
return (
// ...
)
}
import React from "react";
import { useWindowFocus } from "@better-hooks/window";
const MyComponent: React.FC = () => {
// Updates when user leave our page
const focus = useWindowFocus()
useEffect(() => {
if(focus) {
// User is using our page
} else {
// User has minimized window or leaved our page to different tab
}
}, [focus])
return (
// ...
)
}
FAQs
React window hooks
We found that @better-hooks/window 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.