🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

@seznam/compose-react-refs

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@seznam/compose-react-refs - npm Package Compare versions

Comparing version
1.0.3
to
1.0.4
+1
-1
package.json
{
"name": "@seznam/compose-react-refs",
"version": "1.0.3",
"version": "1.0.4",
"description": "A simple utility for composing two or more react refs into a single callback ref.",

@@ -5,0 +5,0 @@ "main": "composeRefs.js",

@@ -43,2 +43,4 @@ # Compose react refs

// No need to worry about nulls and undefined refs here, they will be
// filtered out automatically.
return <input {...props} ref={composeRefs(myRef, externalRef)}/>

@@ -48,3 +50,19 @@ })

The `composeRefs` function allows combining any number of refs:
```typescript jsx
import * as React from 'react'
import composeRefs from '@seznam/compose-react-refs'
export default React.forwardRef((props, externalRef) => {
const myRef = React.useRef(null)
const otherRef = React.useRef(null)
return <input {...props} ref={composeRefs(myRef, null, undefined, otherRef, props.extraRef, externalRef)}/>
})
```
The refs will be updated in the order in which they were provided to the
`composeRefs` function.
`composeRefs` function. The composed ref passed to react is cached (no need to
use [`useMemo`](https://reactjs.org/docs/hooks-reference.html#usememo) in your
code), improving performance and preventing
[unexpected ref updates](https://reactjs.org/docs/refs-and-the-dom.html#caveats-with-callback-refs).