@reach/utils
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -19,12 +19,3 @@ import { useRef, useMemo, useEffect } from "react"; | ||
export { checkStyles }; | ||
export var wrapEvent = function wrapEvent(theirHandler, ourHandler) { | ||
return function (event) { | ||
theirHandler && theirHandler(event); | ||
if (!event.defaultPrevented) { | ||
return ourHandler(event); | ||
} | ||
}; | ||
}; | ||
export var assignRef = function assignRef(ref, value) { | ||
export function assignRef(ref, value) { | ||
if (ref == null) return; | ||
@@ -41,14 +32,15 @@ | ||
} | ||
}; | ||
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 | ||
} | ||
export function getScrollbarOffset() { | ||
try { | ||
if (window.innerWidth > document.documentElement.clientWidth) { | ||
return window.innerWidth - document.documentElement.clientWidth; | ||
} | ||
} catch (err) {} | ||
}, deps); | ||
return 0; | ||
} | ||
export function makeId(id, index) { | ||
return id + "--" + index; | ||
} | ||
export function useForkedRef() { | ||
@@ -73,4 +65,28 @@ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) { | ||
} | ||
export var makeId = function makeId(id, index) { | ||
return id + "--" + index; | ||
}; | ||
export function usePrevious(value) { | ||
var ref = useRef(); | ||
useEffect(function () { | ||
ref.current = value; | ||
}, [value]); | ||
return ref.current; | ||
} | ||
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 wrapEvent(theirHandler, ourHandler) { | ||
return function (event) { | ||
theirHandler && theirHandler(event); | ||
if (!event.defaultPrevented) { | ||
return ourHandler(event); | ||
} | ||
}; | ||
} |
77
index.js
"use strict"; | ||
exports.__esModule = true; | ||
exports.assignRef = assignRef; | ||
exports.getScrollbarOffset = getScrollbarOffset; | ||
exports.makeId = makeId; | ||
exports.useForkedRef = useForkedRef; | ||
exports.usePrevious = usePrevious; | ||
exports.useUpdateEffect = useUpdateEffect; | ||
exports.useForkedRef = useForkedRef; | ||
exports.makeId = exports.assignRef = exports.wrapEvent = exports.checkStyles = void 0; | ||
exports.wrapEvent = wrapEvent; | ||
exports.checkStyles = void 0; | ||
@@ -28,15 +33,3 @@ var _react = require("react"); | ||
var wrapEvent = function wrapEvent(theirHandler, ourHandler) { | ||
return function (event) { | ||
theirHandler && theirHandler(event); | ||
if (!event.defaultPrevented) { | ||
return ourHandler(event); | ||
} | ||
}; | ||
}; | ||
exports.wrapEvent = wrapEvent; | ||
var assignRef = function assignRef(ref, value) { | ||
function assignRef(ref, value) { | ||
if (ref == null) return; | ||
@@ -53,16 +46,16 @@ | ||
} | ||
}; | ||
} | ||
exports.assignRef = assignRef; | ||
function getScrollbarOffset() { | ||
try { | ||
if (window.innerWidth > document.documentElement.clientWidth) { | ||
return window.innerWidth - document.documentElement.clientWidth; | ||
} | ||
} catch (err) {} | ||
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 | ||
return 0; | ||
} | ||
}, deps); | ||
function makeId(id, index) { | ||
return id + "--" + index; | ||
} | ||
@@ -90,6 +83,30 @@ | ||
var makeId = function makeId(id, index) { | ||
return id + "--" + index; | ||
}; | ||
function usePrevious(value) { | ||
var ref = (0, _react.useRef)(); | ||
(0, _react.useEffect)(function () { | ||
ref.current = value; | ||
}, [value]); | ||
return ref.current; | ||
} | ||
exports.makeId = makeId; | ||
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 wrapEvent(theirHandler, ourHandler) { | ||
return function (event) { | ||
theirHandler && theirHandler(event); | ||
if (!event.defaultPrevented) { | ||
return ourHandler(event); | ||
} | ||
}; | ||
} |
{ | ||
"name": "@reach/utils", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Internal, shared utilities for Reach UI.", | ||
@@ -22,3 +22,3 @@ "main": "index.js", | ||
], | ||
"gitHead": "0f3d2c7e530cd80e1d1bd338182ac89a3ba23999" | ||
"gitHead": "7e33672d882cd6df77ac8cdb76b6b4a21dbf28c2" | ||
} |
@@ -39,10 +39,3 @@ import { useRef, useMemo, useEffect } from "react"; | ||
export let wrapEvent = (theirHandler, ourHandler) => event => { | ||
theirHandler && theirHandler(event); | ||
if (!event.defaultPrevented) { | ||
return ourHandler(event); | ||
} | ||
}; | ||
export const assignRef = (ref, value) => { | ||
export function assignRef(ref, value) { | ||
if (ref == null) return; | ||
@@ -58,16 +51,17 @@ if (typeof ref === "function") { | ||
} | ||
}; | ||
} | ||
export function useUpdateEffect(effect, deps) { | ||
const mounted = useRef(false); | ||
useEffect(() => { | ||
if (mounted.current) { | ||
effect(); | ||
} else { | ||
mounted.current = true; | ||
export function getScrollbarOffset() { | ||
try { | ||
if (window.innerWidth > document.documentElement.clientWidth) { | ||
return window.innerWidth - document.documentElement.clientWidth; | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, deps); | ||
} catch (err) {} | ||
return 0; | ||
} | ||
export function makeId(id, index) { | ||
return `${id}--${index}`; | ||
} | ||
export function useForkedRef(...refs) { | ||
@@ -87,2 +81,29 @@ return useMemo(() => { | ||
export const makeId = (id, index) => `${id}--${index}`; | ||
export function usePrevious(value) { | ||
const ref = useRef(); | ||
useEffect(() => { | ||
ref.current = value; | ||
}, [value]); | ||
return ref.current; | ||
} | ||
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 wrapEvent(theirHandler, ourHandler) { | ||
return event => { | ||
theirHandler && theirHandler(event); | ||
if (!event.defaultPrevented) { | ||
return ourHandler(event); | ||
} | ||
}; | ||
} |
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
9507
258