@devboldly/react-use-window-global
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -21,5 +21,9 @@ "use strict"; | ||
var _d = React.useState(defaultValue), reactState = _d[0], setReactState = _d[1]; | ||
var emitterEventName = (namespace !== 'undefined' ? namespace + '.' : '') + keyName + ' change'; | ||
var setStateAndEmit = function (newState) { | ||
setReactState(newState); | ||
getEmitter().emit(emitterEventName); | ||
}; | ||
React.useEffect(function () { | ||
var aborted = false; | ||
var emitterEventName = (namespace !== 'undefined' ? namespace + '.' : '') + keyName + ' change'; | ||
var setStateAndEmit = function (newState) { | ||
@@ -31,3 +35,2 @@ setReactState(newState); | ||
if (typeof window !== 'undefined') { | ||
console.log(window); | ||
var winObj_1 = getWinObj(namespace); | ||
@@ -38,3 +41,3 @@ var emitter = getEmitter(); | ||
// Set up emitter | ||
updateHandler = function (firedById) { | ||
updateHandler = function () { | ||
if (!aborted) { | ||
@@ -81,6 +84,3 @@ setReactState(winObj_1[keyName]); | ||
}; | ||
}, [defaultValue, loaded, keyName, namespace, shouldRestore, reactState, shouldPush]); | ||
var setValue = function (newVal) { | ||
setReactState(newVal); | ||
}; | ||
}, [defaultValue, loaded, keyName, namespace, shouldRestore, reactState, shouldPush, emitterEventName]); | ||
var restore = function () { | ||
@@ -94,3 +94,3 @@ setShouldRestore(true); | ||
var value = reactState; | ||
return { value: value, setValue: setValue, loaded: loaded, reset: reset, restore: restore }; | ||
return { value: value, setValue: setStateAndEmit, loaded: loaded, reset: reset, restore: restore }; | ||
} | ||
@@ -97,0 +97,0 @@ exports.useWindowGlobal = useWindowGlobal; |
{ | ||
"name": "@devboldly/react-use-window-global", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"author": "Dev Boldly <devboldly@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "React hook for setting and getting globals via the Window Web API. Includes namespacing.", |
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
11646