use-memo-one
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -28,5 +28,6 @@ 'use strict'; | ||
})[0]; | ||
var isFirstRun = react.useRef(true); | ||
var committed = react.useRef(initial); | ||
var isInputMatch = Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); | ||
var cache = isInputMatch ? committed.current : { | ||
var useCache = isFirstRun.current || Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); | ||
var cache = useCache ? committed.current : { | ||
inputs: inputs, | ||
@@ -36,2 +37,3 @@ result: getResult() | ||
react.useEffect(function () { | ||
isFirstRun.current = false; | ||
committed.current = cache; | ||
@@ -38,0 +40,0 @@ }, [cache]); |
@@ -24,5 +24,6 @@ import { useState, useRef, useEffect } from 'react'; | ||
})[0]; | ||
var isFirstRun = useRef(true); | ||
var committed = useRef(initial); | ||
var isInputMatch = Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); | ||
var cache = isInputMatch ? committed.current : { | ||
var useCache = isFirstRun.current || Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); | ||
var cache = useCache ? committed.current : { | ||
inputs: inputs, | ||
@@ -32,2 +33,3 @@ result: getResult() | ||
useEffect(function () { | ||
isFirstRun.current = false; | ||
committed.current = cache; | ||
@@ -34,0 +36,0 @@ }, [cache]); |
@@ -28,5 +28,6 @@ (function (global, factory) { | ||
})[0]; | ||
var isFirstRun = react.useRef(true); | ||
var committed = react.useRef(initial); | ||
var isInputMatch = Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); | ||
var cache = isInputMatch ? committed.current : { | ||
var useCache = isFirstRun.current || Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); | ||
var cache = useCache ? committed.current : { | ||
inputs: inputs, | ||
@@ -36,2 +37,3 @@ result: getResult() | ||
react.useEffect(function () { | ||
isFirstRun.current = false; | ||
committed.current = cache; | ||
@@ -38,0 +40,0 @@ }, [cache]); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).useMemoOne={},e.React)}(this,function(e,o){"use strict";function n(e,t){var n=o.useState(function(){return{inputs:t,result:e()}})[0],u=o.useRef(n),r=Boolean(t&&u.current.inputs&&function(e,t){if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(t,u.current.inputs))?u.current:{inputs:t,result:e()};return o.useEffect(function(){u.current=r},[r]),r.result}function t(e,t){return n(function(){return e},t)}var u=n,r=t;e.useCallback=r,e.useCallbackOne=t,e.useMemo=u,e.useMemoOne=n,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).useMemoOne={},e.React)}(this,function(e,o){"use strict";function n(e,t){var n=o.useState(function(){return{inputs:t,result:e()}})[0],u=o.useRef(!0),r=o.useRef(n),f=u.current||Boolean(t&&r.current.inputs&&function(e,t){if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(t,r.current.inputs))?r.current:{inputs:t,result:e()};return o.useEffect(function(){u.current=!1,r.current=f},[f]),f.result}function t(e,t){return n(function(){return e},t)}var u=n,r=t;e.useCallback=r,e.useCallbackOne=t,e.useMemo=u,e.useMemoOne=n,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -17,2 +17,7 @@ type DependencyList = ReadonlyArray<any>; | ||
export { useMemoOne, useCallbackOne }; | ||
export { | ||
useMemoOne, | ||
useCallbackOne, | ||
useMemoOne as useMemo, | ||
useCallbackOne as useCallback | ||
}; |
{ | ||
"name": "use-memo-one", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "useMemo and useCallback but with a stable cache", | ||
@@ -27,3 +27,3 @@ "keywords": [ | ||
"peerDependencies": { | ||
"react": "^16.8.0" | ||
"react": "^16.8.0 || ^17.0.0" | ||
}, | ||
@@ -30,0 +30,0 @@ "devDependencies": { |
@@ -21,15 +21,14 @@ // @flow | ||
}))[0]; | ||
const isFirstRun = useRef<boolean>(true); | ||
const committed = useRef<Cache<T>>(initial); | ||
// persist any uncommitted changes after they have been committed | ||
const isInputMatch: boolean = Boolean( | ||
const useCache: boolean = isFirstRun.current || Boolean( | ||
inputs && | ||
committed.current.inputs && | ||
areInputsEqual(inputs, committed.current.inputs), | ||
committed.current.inputs && | ||
areInputsEqual(inputs, committed.current.inputs), | ||
); | ||
// create a new cache if required | ||
const cache: Cache<T> = isInputMatch | ||
const cache: Cache<T> = useCache | ||
? committed.current | ||
@@ -43,2 +42,3 @@ : { | ||
useEffect(() => { | ||
isFirstRun.current = false; | ||
committed.current = cache; | ||
@@ -45,0 +45,0 @@ }, [cache]); |
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
15710
229