@devboldly/react-use-window-global
Advanced tools
Comparing version 0.0.1 to 0.0.2
/** */ | ||
export declare function useWindowGlobal<T>(keyName: string, defaultValue?: T | undefined, namespace?: string): ExampleHook<T>; | ||
export declare type ExampleHook<T> = [T | undefined, (value: T | undefined) => void, () => void, () => void]; | ||
export declare function useWindowGlobal<T>(keyName: string, defaultValue?: T | undefined, namespace?: string): WindowGlobalHook<T>; | ||
export declare type WindowGlobalHook<T> = { | ||
value: T | undefined; | ||
setValue: (value: T | undefined) => void; | ||
loaded: boolean; | ||
reset: () => void; | ||
restore: () => void; | ||
}; |
@@ -16,3 +16,3 @@ "use strict"; | ||
if (defaultValue === void 0) { defaultValue = undefined; } | ||
var _a = React.useState(true), firstRender = _a[0], setFirstRender = _a[1]; | ||
var _a = React.useState(false), loaded = _a[0], setLoaded = _a[1]; | ||
var _b = React.useState(false), shouldRestore = _b[0], setShouldRestore = _b[1]; | ||
@@ -33,4 +33,3 @@ var _c = React.useState(defaultValue), reactState = _c[0], setReactState = _c[1]; | ||
// Synchronize value with window on first render | ||
if (firstRender) { | ||
setFirstRender(false); | ||
if (!loaded) { | ||
// If on first render we actually have a value, use it. | ||
@@ -44,2 +43,3 @@ if (keyExists()) { | ||
} | ||
setLoaded(true); | ||
} | ||
@@ -61,3 +61,3 @@ // Restore value from window when requested | ||
} | ||
}, [defaultValue, firstRender, keyName, namespace, shouldRestore, reactState]); | ||
}, [defaultValue, loaded, keyName, namespace, shouldRestore, reactState]); | ||
var setValue = function (newVal) { | ||
@@ -73,4 +73,4 @@ setReactState(newVal); | ||
var value = reactState; | ||
return [value, setValue, reset, restore]; | ||
return { value: value, setValue: setValue, loaded: loaded, reset: reset, restore: restore }; | ||
} | ||
exports.useWindowGlobal = useWindowGlobal; |
{ | ||
"name": "@devboldly/react-use-window-global", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"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
9977
87