@react-hook/merged-ref
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -1,15 +0,11 @@ | ||
'use strict' | ||
"use strict"; | ||
exports.__esModule = true | ||
exports.default = void 0 | ||
exports.__esModule = true; | ||
exports.default = void 0; | ||
const useMergedRef = (...args) => (element) => | ||
args.forEach((arg) => setRef(arg, element)) | ||
const useMergedRef = (...refs) => element => refs.forEach(ref => { | ||
if (typeof ref === 'function') ref(element);else if (ref && typeof ref === 'object') ref.current = element; | ||
}); | ||
const setRef = (ref, value) => { | ||
if (typeof ref === 'function') ref(value) | ||
else if (ref && typeof ref === 'object') ref.current = value | ||
} | ||
var _default = useMergedRef | ||
exports.default = _default | ||
var _default = useMergedRef; | ||
exports.default = _default; |
@@ -1,9 +0,5 @@ | ||
const useMergedRef = (...args) => (element) => | ||
args.forEach((arg) => setRef(arg, element)) | ||
const useMergedRef = (...refs) => element => refs.forEach(ref => { | ||
if (typeof ref === 'function') ref(element);else if (ref && typeof ref === 'object') ref.current = element; | ||
}); | ||
const setRef = (ref, value) => { | ||
if (typeof ref === 'function') ref(value) | ||
else if (ref && typeof ref === 'object') ref.current = value | ||
} | ||
export default useMergedRef | ||
export default useMergedRef; |
{ | ||
"name": "@react-hook/merged-ref", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"homepage": "https://github.com/jaredLunde/react-hook/tree/master/packages/merged-ref#readme", | ||
@@ -26,2 +26,3 @@ "repository": "github:jaredLunde/react-hook", | ||
"module": "dist/module/index.js", | ||
"unpkg": "dist/umd/use-merged-ref.js", | ||
"source": "src/index.tsx", | ||
@@ -39,2 +40,3 @@ "types": "types/index.d.ts", | ||
"require": "./dist/main/index.js", | ||
"umd": "./dist/umd/use-merged-ref.js", | ||
"source": "./src/index.tsx", | ||
@@ -49,18 +51,14 @@ "types": "./types/index.d.ts", | ||
"scripts": { | ||
"build": "npm run build-esm && npm run build-main && npm run build-module && npm run build-types", | ||
"build-esm": "npm run compile -- -d dist/esm --env-name esm --out-file-extension .mjs", | ||
"build-main": "npm run compile -- -d dist/main --env-name main", | ||
"build-module": "npm run compile -- -d dist/module --env-name module", | ||
"build-types": "tsc -p tsconfig.json -d --outDir types --emitDeclarationOnly", | ||
"check-types": "tsc --noEmit -p tsconfig.json", | ||
"compile": "babel src -x .ts,.tsx --ignore \"**/*.test.ts\",\"**/*.test.tsx\" --delete-dir-on-start", | ||
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,md,yml,json,eslintrc,prettierrc}\"", | ||
"build": "lundle build --umd-case camel", | ||
"check-types": "lundle check-types", | ||
"dev": "lundle build -f module,cjs -w", | ||
"format": "prettier --write \"{,!(node_modules|dist|coverage)/**/}*.{ts,tsx,js,jsx,md,yml,json}\"", | ||
"lint": "eslint . --ext .ts,.tsx", | ||
"prepublishOnly": "npm run lint && npm run test && npm run build && npm run format", | ||
"test": "jest", | ||
"validate": "npm run check-types && npm run lint && npm run test -- --coverage" | ||
"validate": "lundle check-types && npm run lint && jest --coverage" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "npm run build-types && git add types && lint-staged" | ||
"pre-commit": "lundle check-types && lint-staged" | ||
} | ||
@@ -73,9 +71,45 @@ }, | ||
], | ||
"**/*.{md,yml,json,eslintrc,prettierrc}": [ | ||
"**/*.{md,yml,json}": [ | ||
"prettier --write" | ||
] | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"lunde" | ||
] | ||
}, | ||
"eslintIgnore": [ | ||
"node_modules", | ||
"coverage", | ||
"dist", | ||
"test", | ||
"*.config.js" | ||
], | ||
"jest": { | ||
"moduleDirectories": [ | ||
"node_modules", | ||
"src", | ||
"test" | ||
], | ||
"testMatch": [ | ||
"<rootDir>/src/**/?(*.)test.{ts,tsx}" | ||
], | ||
"collectCoverageFrom": [ | ||
"**/src/**/*.{ts,tsx}" | ||
], | ||
"setupFilesAfterEnv": [ | ||
"./test/setup.js" | ||
], | ||
"snapshotResolver": "./test/resolve-snapshot.js", | ||
"globals": { | ||
"__DEV__": true | ||
} | ||
}, | ||
"prettier": { | ||
"semi": false, | ||
"singleQuote": true, | ||
"jsxSingleQuote": true, | ||
"bracketSpacing": false | ||
}, | ||
"devDependencies": { | ||
"@babel/preset-react": "latest", | ||
"@lunde/babel-preset-es": "latest", | ||
"@testing-library/jest-dom": "latest", | ||
@@ -88,14 +122,9 @@ "@testing-library/react": "latest", | ||
"@types/react-dom": "latest", | ||
"@typescript-eslint/eslint-plugin": "latest", | ||
"@typescript-eslint/parser": "latest", | ||
"babel-plugin-annotate-pure-calls": "latest", | ||
"babel-plugin-optimize-react": "latest", | ||
"babel-jest": "latest", | ||
"eslint": "latest", | ||
"eslint-import-resolver-jest": "latest", | ||
"eslint-plugin-jest": "latest", | ||
"eslint-plugin-react": "latest", | ||
"eslint-plugin-react-hooks": "latest", | ||
"eslint-config-lunde": "latest", | ||
"husky": "latest", | ||
"jest": "latest", | ||
"lint-staged": "latest", | ||
"lundle": "latest", | ||
"prettier": "latest", | ||
@@ -105,3 +134,2 @@ "react": "latest", | ||
"react-test-renderer": "latest", | ||
"ts-jest": "latest", | ||
"typescript": "latest" | ||
@@ -111,5 +139,4 @@ }, | ||
"peerDependencies": { | ||
"react": ">=16.8", | ||
"react-dom": ">=16.8" | ||
"react": ">=16.8" | ||
} | ||
} |
@@ -43,4 +43,10 @@ <hr> | ||
### `useMergedRef(...refs: ReactRef[]): CallbackRef` | ||
### `useMergedRef(...refs)` | ||
```ts | ||
function useMergedRef<T extends any>( | ||
...refs: React.Ref<T>[] | ||
): React.RefCallback<T> | ||
``` | ||
| Argument | Description | | ||
@@ -50,3 +56,3 @@ | -------- | ------------------------------------------------------------------ | | ||
#### Returns `ref: CallbackRef` | ||
#### Returns `React.RefCallback` | ||
@@ -53,0 +59,0 @@ Returns a callback ref |
import * as React from 'react' | ||
declare const useMergedRef: <T extends unknown = any>( | ||
...args: ReactRef<T>[] | ||
) => CallbackRef<T> | ||
export declare type CallbackRef<T> = (element: T) => void | ||
export declare type ReactRef<T> = | ||
| CallbackRef<T | null> | ||
| React.MutableRefObject<T | null> | ||
| null | ||
declare const useMergedRef: <T extends unknown>( | ||
...refs: React.Ref<T>[] | ||
) => (instance: T | null) => void | ||
export default useMergedRef |
Sorry, the diff of this file is not supported yet
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
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
10223
1
19
13
62
54