@reach/utils
Advanced tools
Comparing version 0.2.3 to 0.3.0-alpha.0
@@ -0,1 +1,2 @@ | ||
import { useRef, useMemo, useEffect } from "react"; | ||
var checkedPkgs = {}; | ||
@@ -18,6 +19,6 @@ | ||
export { checkStyles }; | ||
export var wrapEvent = function wrapEvent(theirHandler, ourHandler) { | ||
return function (event) { | ||
theirHandler && theirHandler(event); | ||
if (!event.defaultPrevented) { | ||
@@ -28,5 +29,5 @@ return ourHandler(event); | ||
}; | ||
export var assignRef = function assignRef(ref, value) { | ||
if (ref == null) return; | ||
if (typeof ref === "function") { | ||
@@ -41,2 +42,36 @@ ref(value); | ||
} | ||
}; | ||
}; | ||
export function useUpdateEffect(effect, deps) { | ||
var mounted = useRef(false); | ||
useEffect(function () { | ||
if (mounted.current) { | ||
effect(); | ||
} else { | ||
mounted.current = true; | ||
} // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, deps); | ||
} | ||
export function useAssignRef(refA, refB) { | ||
var ref = useMemo(function () { | ||
if (refA == null && refB == null) { | ||
return null; | ||
} | ||
return function (refValue) { | ||
setRef(refA, refValue); | ||
setRef(refB, refValue); | ||
}; | ||
}, [refA, refB]); // We shouldn't really need to throw an error using this method AFAICT. | ||
// TODO: We may want to consider phasing out `assignRef` in favor of this hook. | ||
function setRef(ref, value) { | ||
if (typeof ref === "function") { | ||
ref(value); | ||
} else if (ref) { | ||
ref.current = value; | ||
} | ||
} | ||
return ref; | ||
} |
57
index.js
"use strict"; | ||
exports.__esModule = true; | ||
exports.useUpdateEffect = useUpdateEffect; | ||
exports.useAssignRef = useAssignRef; | ||
exports.assignRef = exports.wrapEvent = exports.checkStyles = void 0; | ||
var _react = require("react"); | ||
var checkedPkgs = {}; | ||
@@ -8,2 +14,4 @@ | ||
exports.checkStyles = checkStyles; | ||
if (process.env.NODE_ENV !== "production") { | ||
@@ -21,6 +29,6 @@ exports.checkStyles = checkStyles = function checkStyles(pkg) { | ||
exports.checkStyles = checkStyles; | ||
var wrapEvent = exports.wrapEvent = function wrapEvent(theirHandler, ourHandler) { | ||
var wrapEvent = function wrapEvent(theirHandler, ourHandler) { | ||
return function (event) { | ||
theirHandler && theirHandler(event); | ||
if (!event.defaultPrevented) { | ||
@@ -32,4 +40,7 @@ return ourHandler(event); | ||
var assignRef = exports.assignRef = function assignRef(ref, value) { | ||
exports.wrapEvent = wrapEvent; | ||
var assignRef = function assignRef(ref, value) { | ||
if (ref == null) return; | ||
if (typeof ref === "function") { | ||
@@ -44,2 +55,40 @@ ref(value); | ||
} | ||
}; | ||
}; | ||
exports.assignRef = assignRef; | ||
function useUpdateEffect(effect, deps) { | ||
var mounted = (0, _react.useRef)(false); | ||
(0, _react.useEffect)(function () { | ||
if (mounted.current) { | ||
effect(); | ||
} else { | ||
mounted.current = true; | ||
} // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, deps); | ||
} | ||
function useAssignRef(refA, refB) { | ||
var ref = (0, _react.useMemo)(function () { | ||
if (refA == null && refB == null) { | ||
return null; | ||
} | ||
return function (refValue) { | ||
setRef(refA, refValue); | ||
setRef(refB, refValue); | ||
}; | ||
}, [refA, refB]); // We shouldn't really need to throw an error using this method AFAICT. | ||
// TODO: We may want to consider phasing out `assignRef` in favor of this hook. | ||
function setRef(ref, value) { | ||
if (typeof ref === "function") { | ||
ref(value); | ||
} else if (ref) { | ||
ref.current = value; | ||
} | ||
} | ||
return ref; | ||
} |
{ | ||
"name": "@reach/utils", | ||
"version": "0.2.3", | ||
"version": "0.3.0-alpha.0", | ||
"description": "Internal, shared utilities for Reach UI.", | ||
@@ -8,3 +8,2 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Write some tests you bum!\"", | ||
"build": "node ../../shared/build-package", | ||
@@ -17,3 +16,3 @@ "lint": "eslint . --max-warnings=0" | ||
}, | ||
"author": "Ryan Florence", | ||
"author": "Ryan Florence <@ryanflorence>", | ||
"license": "MIT", | ||
@@ -25,3 +24,4 @@ "files": [ | ||
"index.js" | ||
] | ||
], | ||
"gitHead": "3234e9cf2a55f51c31ac5a7d883d34d6be6f033d" | ||
} |
@@ -0,1 +1,3 @@ | ||
import { useRef, useMemo, useEffect } from "react"; | ||
let checkedPkgs = {}; | ||
@@ -56,1 +58,37 @@ | ||
}; | ||
export function useUpdateEffect(effect, deps) { | ||
const mounted = useRef(false); | ||
useEffect(() => { | ||
if (mounted.current) { | ||
effect(); | ||
} else { | ||
mounted.current = true; | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, deps); | ||
} | ||
export function useAssignRef(refA, refB) { | ||
const ref = useMemo(() => { | ||
if (refA == null && refB == null) { | ||
return null; | ||
} | ||
return refValue => { | ||
setRef(refA, refValue); | ||
setRef(refB, refValue); | ||
}; | ||
}, [refA, refB]); | ||
// We shouldn't really need to throw an error using this method AFAICT. | ||
// TODO: We may want to consider phasing out `assignRef` in favor of this hook. | ||
function setRef(ref, value) { | ||
if (typeof ref === "function") { | ||
ref(value); | ||
} else if (ref) { | ||
ref.current = value; | ||
} | ||
} | ||
return ref; | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
8679
213
5
3
1