Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@reach/utils

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reach/utils - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0-alpha.0

LICENSE

41

es/index.js

@@ -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;
}
"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;
}

8

package.json
{
"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;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc