Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
react-use-observer
Advanced tools
Performant react hooks for WebApi Observers, useResizeObserver, useInteractionObserver, useMutationObserver
Performant react hooks for WebApi Observers
Does not include pollyfills for ResizeObserver
and IntersectionObserver
if you need to support older browsers please include polyfills for them.
npm install react-use-observer
or
npm install --save react-use-observer
[ref: React Ref, entry: ResizeObserverEntry]
import { useResizeObserver } from 'react-use-observer'
const App = () => {
const [ref, resizeObserverEntry] = useResizeObserver()
const { width = 0 } = resizeObserverEntry.contentRect || {}
return (
<div ref={ref}>
width: {width}
</div>
)
}
options: Object - Initialization
options for IntersectionObserver
root: An Element object which is an ancestor of the intended target, whose bounding rectangle will be considered the viewport. Any part of the target not visible in the visible area of the root is not considered visible.
rootMargin: A string which specifies a set of offsets to add to the root's bounding_box when calculating intersections, effectively shrinking or growing the root for calculation purposes. The syntax is approximately the same as that for the CSS margin property; see The root element and root margin in Intersection Observer API for more information on how the margin works and the syntax. The default is "0px 0px 0px 0px".
threshold: Either a single number or an array of numbers between 0.0 and 1.0, specifying a ratio of intersection area to total bounding box area for the observed target. A value of 0.0 means that even a single visible pixel counts as the target being visible. 1.0 means that the entire target element is visible. See Thresholds in Intersection Observer API for a more in-depth description of how thresholds are used. The default is a threshold of 0.0.
[ref: React Ref, entry: IntersectionObserverEntry]
import { useIntersectionObserver } from 'react-use-observer'
const MyComp = () => {
const [ref, intersectionObserverEntry] = useIntersectionObserver({
root: null,
rootMargin: '0px',
threshold: 0.5
})
return (
<div ref={ref}>
{intersectionObserverEntry.intersectionRatio}
</div>
)
}
options: MutationObserverInit - Options to pass observe
method of MutationObserver
attributeFilter: An array of specific attribute names to be monitored. If this property isn't included, changes to all attributes cause mutation notifications. No default value.
attributeOldValue: Set to true to record the previous value of any attribute that changes when monitoring the node or nodes for attribute changes; see Monitoring attribute values in MutationObserver for details on watching for attribute changes and value recording. No default value.
attributes: Set to true to watch for changes to the value of attributes on the node or nodes being monitored. The default value is false.
characterData: Set to true to monitor the specified target node or subtree for changes to the character data contained within the node or nodes. No default value.
characterDataOldValue: Set to true to record the previous value of a node's text whenever the text changes on nodes being monitored. For details and an example, see Monitoring text content changes in MutationObserver. No default value.
childList: Set to true to monitor the target node (and, if subtree is true, its descendants) for the addition of new child nodes or removal of existing child nodes. The default is false.
subtree: Set to true to extend monitoring to the entire subtree of nodes rooted at target. All of the other MutationObserverInit properties are then extended to all of the nodes in the subtree instead of applying solely to the target node. The default value is false.
[ref: React Ref, entry: MutationRecord]
import { useMutationObserver } from 'react-use-observer'
const MyComp = () => {
const [ref, mutationRecord] = useMutationObserver({
attributes: true,
childList: true,
subtree: true,
})
return (
<div>
Mutation Type { mutationRecord.type }
</div>
)
}
Observer: (Any WebApi Observer)
options: Object
Initialization
options for given Observer
observe
method of Observer
[ref: React Ref, entry: ObserverEntry]
import { useObserver } from 'react-use-observer'
const MyComp = () => {
const [ref, entry] = useObserver(PerformanceObserver, {
subscribeOptions: {
entryTypes: ['frame'],
},
})
return (
<div>
Entry Type { entry.entryType }
</div>
)
}
MIT © ardaogulcan
FAQs
Performant react hooks for WebApi Observers, useResizeObserver, useInteractionObserver, useMutationObserver
We found that react-use-observer 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.