vaderjs 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +8 -4
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -384,8 +384,13 @@ export class Component {
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
|
|
387
|
-
|
|
387
|
+
useState(key, defaultValue, persist = false) {
|
|
388
388
|
let value = this.state[key] || defaultValue;
|
|
389
|
+
if(value === "true" || value === "false") {
|
|
390
|
+
value = JSON.parse(value);
|
|
391
|
+
}
|
|
392
|
+
// if value is boolean store as string
|
|
393
|
+
|
|
389
394
|
if (persist) {
|
|
390
395
|
value = sessionStorage.getItem(key) ? JSON.parse(sessionStorage.getItem(key)).value : defaultValue;
|
|
391
396
|
}
|
|
@@ -393,13 +398,12 @@ export class Component {
|
|
|
393
398
|
if(typeof newValue === "function") {
|
|
394
399
|
newValue = newValue(this.state[key]);
|
|
395
400
|
}
|
|
396
|
-
this.state[key] = newValue;
|
|
401
|
+
this.state[key] = typeof newValue === "boolean" ? newValue.toString() : newValue;
|
|
397
402
|
if (persist) {
|
|
398
403
|
sessionStorage.setItem(key, JSON.stringify({ value: newValue }));
|
|
399
404
|
}
|
|
400
405
|
this.forceUpdate(this.key);
|
|
401
|
-
};
|
|
402
|
-
value = this.state[key] || defaultValue;
|
|
406
|
+
};
|
|
403
407
|
return [value, setValue];
|
|
404
408
|
}
|
|
405
409
|
useFetch(url, options) {
|