@quanta-lib/q-state 1.1.5 → 1.1.7
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/README.md +2 -2
- package/dist/Q-State-Engine.js +9 -2
- package/package.json +4 -1
- package/src/Q-State-Engine.ts +6 -1
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
A lightweight React state management engine using `useSyncExternalStore` with optional localStorage caching and value transformation.
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# Small issue (FIXED)
|
|
6
6
|
|
|
7
7
|
Hey i have an isssue, when you use nextjs with this library, just copy the engine code in the q-state file
|
|
8
8
|
because this library had hydration issue, after you copy it, use it inside your src file, so this library can work
|
|
9
|
-
well in nextjs, im sorry for that...
|
|
9
|
+
well in nextjs, im sorry for that... (BUG FIXED, Q-STATE COMPATIBLE WITH NEXTJS NOW!)
|
|
10
10
|
|
|
11
11
|
# Github link
|
|
12
12
|
|
package/dist/Q-State-Engine.js
CHANGED
|
@@ -23,7 +23,13 @@ var Q_StateEngine = /** @class */ (function () {
|
|
|
23
23
|
_this.listener.forEach(function (cb) { return cb(); });
|
|
24
24
|
};
|
|
25
25
|
this.useQuantaState = function (key) {
|
|
26
|
-
|
|
26
|
+
(0, react_1.useEffect)(function () {
|
|
27
|
+
var _a;
|
|
28
|
+
if (!((_a = _this.option) === null || _a === void 0 ? void 0 : _a.cache) && typeof window !== 'undefined') {
|
|
29
|
+
localStorage.removeItem(key);
|
|
30
|
+
}
|
|
31
|
+
}, []);
|
|
32
|
+
var getCurrAfterRender = function () {
|
|
27
33
|
var _a;
|
|
28
34
|
if (((_a = _this.option) === null || _a === void 0 ? void 0 : _a.cache) && typeof window !== "undefined") {
|
|
29
35
|
var getcache = localStorage.getItem(key);
|
|
@@ -42,7 +48,8 @@ var Q_StateEngine = /** @class */ (function () {
|
|
|
42
48
|
}
|
|
43
49
|
return _this.obj[key];
|
|
44
50
|
};
|
|
45
|
-
var
|
|
51
|
+
var defaultValue = null;
|
|
52
|
+
var syncSpecificData = (0, react_1.useSyncExternalStore)(_this.subsribe, function () { return getCurrAfterRender(); }, function () { return defaultValue; });
|
|
46
53
|
return [syncSpecificData];
|
|
47
54
|
};
|
|
48
55
|
this.obj = state;
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quanta-lib/q-state",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "A lightweight React state management library using `useSyncExternalStore` with optional localStorage caching and value transformation.",
|
|
5
5
|
"main": "dist/Q-State-Engine.js",
|
|
6
6
|
"types": "src/Q-State-Engine.ts",
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"react": ">=18.0.0"
|
|
9
|
+
},
|
|
7
10
|
"files": [
|
|
8
11
|
"dist",
|
|
9
12
|
"src"
|
package/src/Q-State-Engine.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useSyncExternalStore } from "react"
|
|
1
|
+
import { useEffect, useSyncExternalStore } from "react"
|
|
2
2
|
|
|
3
3
|
interface OptionRecord {
|
|
4
4
|
cache: boolean
|
|
@@ -38,6 +38,11 @@ export class Q_StateEngine
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
useQuantaState = <K extends keyof T>(key: K): [T[K]] => {
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!this.option?.cache && typeof window !== 'undefined') {
|
|
43
|
+
localStorage.removeItem(key as string)
|
|
44
|
+
}
|
|
45
|
+
}, [])
|
|
41
46
|
const getCurrAfterRender = () => {
|
|
42
47
|
if (this.option?.cache && typeof window !== "undefined") {
|
|
43
48
|
const getcache = localStorage.getItem(key as string)
|