Comparing version 1.0.0 to 1.1.0
@@ -14,22 +14,21 @@ /** | ||
export default function mergeRefs() { | ||
for (var _len = arguments.length, inputRefs = new Array(_len), _key = 0; _key < _len; _key++) { | ||
inputRefs[_key] = arguments[_key]; | ||
} | ||
var filteredInputRefs = inputRefs.filter(Boolean); | ||
if (filteredInputRefs.length <= 1) { | ||
return filteredInputRefs[0]; | ||
} | ||
return function mergedRefs(ref) { | ||
filteredInputRefs.forEach(function (inputRef) { | ||
if (typeof inputRef === 'function') { | ||
inputRef(ref); | ||
} else { | ||
// eslint-disable-next-line no-param-reassign | ||
inputRef.current = ref; | ||
} | ||
}); | ||
}; | ||
} | ||
var inputRefs = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
inputRefs[_i] = arguments[_i]; | ||
} | ||
var filteredInputRefs = inputRefs.filter(Boolean); | ||
if (filteredInputRefs.length <= 1) { | ||
var firstRef = filteredInputRefs[0]; | ||
return firstRef; | ||
} | ||
return function mergedRefs(ref) { | ||
filteredInputRefs.forEach(function (inputRef) { | ||
if (typeof inputRef === 'function') { | ||
inputRef(ref); | ||
} | ||
else if (inputRef) { | ||
inputRef.current = ref; | ||
} | ||
}); | ||
}; | ||
} |
{ | ||
"name": "merge-refs", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A function that merges React refs into one.", | ||
"main": "dist/umd/index.js", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"source": "src/index.js", | ||
"source": "src/index.ts", | ||
"types": "src/index.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"build": "yarn build-esm && yarn build-umd", | ||
"build-esm": "cross-env BABEL_ENV=production-esm babel src -d dist/esm --ignore **/*.spec.js", | ||
"build-umd": "cross-env BABEL_ENV=production-umd babel src -d dist/umd --ignore **/*.spec.js", | ||
"build": "yarn build-esm && yarn build-cjs", | ||
"build-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext", | ||
"build-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs", | ||
"clean": "rimraf dist", | ||
"jest": "jest", | ||
"jest-coverage": "jest --coverage", | ||
"lint": "eslint src/ --ext .jsx,.js", | ||
"prepublishOnly": "yarn clean && yarn build", | ||
"test": "yarn lint && yarn jest" | ||
"lint": "eslint src", | ||
"prepack": "yarn clean && yarn build", | ||
"prettier": "prettier --check . --cache", | ||
"test": "yarn lint && yarn prettier && yarn jest" | ||
}, | ||
@@ -31,19 +32,32 @@ "keywords": [ | ||
"license": "MIT", | ||
"dependencies": { | ||
"@types/react": "*" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.5.5", | ||
"@babel/core": "^7.5.5", | ||
"@babel/preset-env": "^7.5.5", | ||
"babel-jest": "^24.0.0", | ||
"cross-env": "^6.0.3", | ||
"eslint": "^6.1.0", | ||
"eslint-config-airbnb-base": "^14.0.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"jest": "^24.8.0", | ||
"rimraf": "^3.0.0" | ||
"@babel/core": "^7.15.0", | ||
"@babel/preset-env": "^7.15.0", | ||
"@babel/preset-react": "^7.14.0", | ||
"@babel/preset-typescript": "^7.18.6", | ||
"@testing-library/react": "^13.4.0", | ||
"@types/jest": "^29.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.41.0", | ||
"@typescript-eslint/parser": "^5.44.0", | ||
"eslint": "^8.26.0", | ||
"eslint-config-wojtekmaj": "^0.7.1", | ||
"husky": "^8.0.0", | ||
"jest": "^29.0.0", | ||
"jest-environment-jsdom": "^29.0.0", | ||
"prettier": "^2.7.0", | ||
"pretty-quick": "^3.1.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"rimraf": "^3.0.0", | ||
"typescript": "^4.9.4" | ||
}, | ||
"resolutions": { | ||
"semver@7.0.0": "^7.0.0" | ||
}, | ||
"files": [ | ||
"LICENSE", | ||
"README.md", | ||
"dist/", | ||
"src/" | ||
"dist", | ||
"src" | ||
], | ||
@@ -53,3 +67,5 @@ "repository": { | ||
"url": "https://github.com/wojtekmaj/merge-refs.git" | ||
} | ||
} | ||
}, | ||
"funding": "https://github.com/wojtekmaj/merge-refs?sponsor=1", | ||
"packageManager": "yarn@3.1.0" | ||
} |
@@ -1,16 +0,19 @@ | ||
[![npm](https://img.shields.io/npm/v/merge-refs.svg)](https://www.npmjs.com/package/merge-refs) ![downloads](https://img.shields.io/npm/dt/merge-refs.svg) ![build](https://img.shields.io/travis/wojtekmaj/merge-refs/master.svg) ![dependencies](https://img.shields.io/david/wojtekmaj/merge-refs.svg) ![dev dependencies](https://img.shields.io/david/dev/wojtekmaj/merge-refs.svg) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) | ||
[![npm](https://img.shields.io/npm/v/merge-refs.svg)](https://www.npmjs.com/package/merge-refs) ![downloads](https://img.shields.io/npm/dt/merge-refs.svg) [![CI](https://github.com/wojtekmaj/merge-refs/workflows/CI/badge.svg)](https://github.com/wojtekmaj/merge-refs/actions) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) | ||
# Merge-Refs | ||
A function that merges React refs into one. Filters out invalid (eg. falsy) refs as well and returns original ref if only one valid ref was given. | ||
## tl;dr | ||
* Install by executing `npm install merge-refs` or `yarn add merge-refs`. | ||
* Import by adding `import mergeRefs from 'merge-refs'`. | ||
* Pass arguments to it. Forget. | ||
- Install by executing `npm install merge-refs` or `yarn add merge-refs`. | ||
- Import by adding `import mergeRefs from 'merge-refs'`. | ||
- Use it in `ref` like so: `<div ref={mergeRefs(ref, someOtherRef)} />` | ||
## Accepted refs | ||
* Refs created using `React.createRef()` | ||
* Refs created using `React.useRef()` | ||
* Functional refs | ||
- Refs created using `React.createRef()` | ||
- Refs created using `React.useRef()` | ||
- Functional refs | ||
## Example | ||
@@ -25,5 +28,3 @@ | ||
return ( | ||
<div ref={mergeRefs(ref1, ref2)} /> | ||
); | ||
return <div ref={mergeRefs(ref1, ref2)} />; | ||
} | ||
@@ -46,5 +47,5 @@ ``` | ||
<a href="mailto:kontakt@wojtekmaj.pl">kontakt@wojtekmaj.pl</a><br /> | ||
<a href="http://wojtekmaj.pl">http://wojtekmaj.pl</a> | ||
<a href="https://wojtekmaj.pl">https://wojtekmaj.pl</a> | ||
</td> | ||
</tr> | ||
</table> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13687
13
270
50
1
19
1
+ Added@types/react@*
+ Added@types/prop-types@15.7.13(transitive)
+ Added@types/react@18.3.12(transitive)
+ Addedcsstype@3.1.3(transitive)