@pdg/react-hook 2.0.23 → 2.0.24

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/dist/index.esm.js CHANGED
@@ -155,7 +155,28 @@ function _unsupportedIterableToArray(r, a) {
155
155
  t0 = $[1];
156
156
  }
157
157
  useLayoutEffect(t0, deps);
158
- };function useMountedRef(t0) {
158
+ };function useMounted(t0) {
159
+ var $ = c(1);
160
+ var initialValue = t0 === undefined ? true : t0;
161
+ var _useState = useState(initialValue),
162
+ _useState2 = _slicedToArray(_useState, 2),
163
+ isMounted = _useState2[0],
164
+ setIsMounted = _useState2[1];
165
+ var t1;
166
+ if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
167
+ t1 = function t1() {
168
+ setIsMounted(true);
169
+ return function () {
170
+ setIsMounted(false);
171
+ };
172
+ };
173
+ $[0] = t1;
174
+ } else {
175
+ t1 = $[0];
176
+ }
177
+ useEventEffect(t1);
178
+ return isMounted;
179
+ }function useMountedRef(t0) {
159
180
  var $ = c(2);
160
181
  var initialValue = t0 === undefined ? true : t0;
161
182
  var isMountedRef = useRef(initialValue);
@@ -315,4 +336,4 @@ function _unsupportedIterableToArray(r, a) {
315
336
  t3 = $[7];
316
337
  }
317
338
  useEffect(t2, t3);
318
- }export{clearIntervalRef,clearTimeoutRef,useAutoUpdateRef,useChanged,useEventEffect,useEventLayoutEffect,useFirstSkipChanged,useFirstSkipEffect,useFirstSkipLayoutEffect,useForwardRef,useIntervalRef,useMountedRef,useTimeoutRef};
339
+ }export{clearIntervalRef,clearTimeoutRef,useAutoUpdateRef,useChanged,useEventEffect,useEventLayoutEffect,useFirstSkipChanged,useFirstSkipEffect,useFirstSkipLayoutEffect,useForwardRef,useIntervalRef,useMounted,useMountedRef,useTimeoutRef};
package/dist/index.js CHANGED
@@ -155,7 +155,28 @@ function _unsupportedIterableToArray(r, a) {
155
155
  t0 = $[1];
156
156
  }
157
157
  react.useLayoutEffect(t0, deps);
158
- };function useMountedRef(t0) {
158
+ };function useMounted(t0) {
159
+ var $ = compilerRuntime.c(1);
160
+ var initialValue = t0 === undefined ? true : t0;
161
+ var _useState = react.useState(initialValue),
162
+ _useState2 = _slicedToArray(_useState, 2),
163
+ isMounted = _useState2[0],
164
+ setIsMounted = _useState2[1];
165
+ var t1;
166
+ if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
167
+ t1 = function t1() {
168
+ setIsMounted(true);
169
+ return function () {
170
+ setIsMounted(false);
171
+ };
172
+ };
173
+ $[0] = t1;
174
+ } else {
175
+ t1 = $[0];
176
+ }
177
+ useEventEffect(t1);
178
+ return isMounted;
179
+ }function useMountedRef(t0) {
159
180
  var $ = compilerRuntime.c(2);
160
181
  var initialValue = t0 === undefined ? true : t0;
161
182
  var isMountedRef = react.useRef(initialValue);
@@ -315,4 +336,4 @@ function _unsupportedIterableToArray(r, a) {
315
336
  t3 = $[7];
316
337
  }
317
338
  react.useEffect(t2, t3);
318
- }exports.clearIntervalRef=clearIntervalRef;exports.clearTimeoutRef=clearTimeoutRef;exports.useAutoUpdateRef=useAutoUpdateRef;exports.useChanged=useChanged;exports.useEventEffect=useEventEffect;exports.useEventLayoutEffect=useEventLayoutEffect;exports.useFirstSkipChanged=useFirstSkipChanged;exports.useFirstSkipEffect=useFirstSkipEffect;exports.useFirstSkipLayoutEffect=useFirstSkipLayoutEffect;exports.useForwardRef=useForwardRef;exports.useIntervalRef=useIntervalRef;exports.useMountedRef=useMountedRef;exports.useTimeoutRef=useTimeoutRef;
339
+ }exports.clearIntervalRef=clearIntervalRef;exports.clearTimeoutRef=clearTimeoutRef;exports.useAutoUpdateRef=useAutoUpdateRef;exports.useChanged=useChanged;exports.useEventEffect=useEventEffect;exports.useEventLayoutEffect=useEventLayoutEffect;exports.useFirstSkipChanged=useFirstSkipChanged;exports.useFirstSkipEffect=useFirstSkipEffect;exports.useFirstSkipLayoutEffect=useFirstSkipLayoutEffect;exports.useForwardRef=useForwardRef;exports.useIntervalRef=useIntervalRef;exports.useMounted=useMounted;exports.useMountedRef=useMountedRef;exports.useTimeoutRef=useTimeoutRef;
@@ -1 +1,2 @@
1
+ export * from './useMounted';
1
2
  export * from './useMountedRef';
@@ -0,0 +1 @@
1
+ export declare function useMounted(initialValue?: boolean): boolean;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@pdg/react-hook",
3
3
  "title": "Typescript React Hook Module",
4
4
  "description": "Typescript React Hook Module",
5
- "version": "2.0.23",
5
+ "version": "2.0.24",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.esm.js",
@@ -12,8 +12,7 @@
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.esm.js",
14
14
  "require": "./dist/index.js"
15
- },
16
- "./eslint-plugin": "./dist/eslint-plugin.js"
15
+ }
17
16
  },
18
17
  "repository": {
19
18
  "type": "git",
@@ -1,158 +0,0 @@
1
- declare const plugin: {
2
- rules: {
3
- 'exhaustive-deps': {
4
- create(context: any): {
5
- CallExpression(node: any): void;
6
- };
7
- meta: {
8
- type: "suggestion";
9
- docs: {
10
- description: string;
11
- recommended: true;
12
- url: string;
13
- };
14
- fixable: "code";
15
- hasSuggestions: true;
16
- schema: {
17
- type: "object";
18
- additionalProperties: false;
19
- enableDangerousAutofixThisMayCauseInfiniteLoops: boolean;
20
- properties: {
21
- additionalHooks: {
22
- type: "string";
23
- };
24
- enableDangerousAutofixThisMayCauseInfiniteLoops: {
25
- type: "boolean";
26
- };
27
- experimental_autoDependenciesHooks: {
28
- type: "array";
29
- items: {
30
- type: "string";
31
- };
32
- };
33
- requireExplicitEffectDeps: {
34
- type: "boolean";
35
- };
36
- };
37
- }[];
38
- };
39
- };
40
- 'rules-of-hooks': {
41
- meta: {
42
- type: "problem";
43
- docs: {
44
- description: string;
45
- recommended: true;
46
- url: string;
47
- };
48
- schema: {
49
- type: "object";
50
- additionalProperties: false;
51
- properties: {
52
- additionalHooks: {
53
- type: "string";
54
- };
55
- };
56
- }[];
57
- };
58
- create(context: import("eslint").Rule.RuleContext): {
59
- "*"(node: any): void;
60
- "*:exit"(node: any): void;
61
- CallExpression(node: import("estree").CallExpression & import("eslint").Rule.NodeParentExtension): void;
62
- Identifier(node: import("estree").Identifier & import("eslint").Rule.NodeParentExtension): void;
63
- "CallExpression:exit"(node: import("estree").CallExpression & import("eslint").Rule.NodeParentExtension): void;
64
- FunctionDeclaration(node: import("estree").FunctionDeclaration & import("eslint").Rule.NodeParentExtension): void;
65
- ArrowFunctionExpression(node: import("estree").ArrowFunctionExpression & import("eslint").Rule.NodeParentExtension): void;
66
- };
67
- };
68
- };
69
- configs: {
70
- recommended: {
71
- plugins: string[];
72
- rules: {
73
- '@pdg/react-hook/rules-of-hooks': string;
74
- '@pdg/react-hook/exhaustive-deps': string;
75
- };
76
- };
77
- flat: {
78
- recommended: {
79
- plugins: {
80
- '@pdg/react-hook': {
81
- rules: {
82
- 'exhaustive-deps': {
83
- create(context: any): {
84
- CallExpression(node: any): void;
85
- };
86
- meta: {
87
- type: "suggestion";
88
- docs: {
89
- description: string;
90
- recommended: true;
91
- url: string;
92
- };
93
- fixable: "code";
94
- hasSuggestions: true;
95
- schema: {
96
- type: "object";
97
- additionalProperties: false;
98
- enableDangerousAutofixThisMayCauseInfiniteLoops: boolean;
99
- properties: {
100
- additionalHooks: {
101
- type: "string";
102
- };
103
- enableDangerousAutofixThisMayCauseInfiniteLoops: {
104
- type: "boolean";
105
- };
106
- experimental_autoDependenciesHooks: {
107
- type: "array";
108
- items: {
109
- type: "string";
110
- };
111
- };
112
- requireExplicitEffectDeps: {
113
- type: "boolean";
114
- };
115
- };
116
- }[];
117
- };
118
- };
119
- 'rules-of-hooks': {
120
- meta: {
121
- type: "problem";
122
- docs: {
123
- description: string;
124
- recommended: true;
125
- url: string;
126
- };
127
- schema: {
128
- type: "object";
129
- additionalProperties: false;
130
- properties: {
131
- additionalHooks: {
132
- type: "string";
133
- };
134
- };
135
- }[];
136
- };
137
- create(context: import("eslint").Rule.RuleContext): {
138
- "*"(node: any): void;
139
- "*:exit"(node: any): void;
140
- CallExpression(node: import("estree").CallExpression & import("eslint").Rule.NodeParentExtension): void;
141
- Identifier(node: import("estree").Identifier & import("eslint").Rule.NodeParentExtension): void;
142
- "CallExpression:exit"(node: import("estree").CallExpression & import("eslint").Rule.NodeParentExtension): void;
143
- FunctionDeclaration(node: import("estree").FunctionDeclaration & import("eslint").Rule.NodeParentExtension): void;
144
- ArrowFunctionExpression(node: import("estree").ArrowFunctionExpression & import("eslint").Rule.NodeParentExtension): void;
145
- };
146
- };
147
- };
148
- };
149
- };
150
- rules: {
151
- '@pdg/react-hook/rules-of-hooks': string;
152
- '@pdg/react-hook/exhaustive-deps': string;
153
- };
154
- };
155
- };
156
- };
157
- };
158
- export default plugin;
@@ -1,106 +0,0 @@
1
- import reactHooksPlugin from 'eslint-plugin-react-hooks';
2
-
3
- const pluginRules = {
4
- rules: {
5
- 'exhaustive-deps': Object.assign(Object.assign({}, reactHooksPlugin.rules['exhaustive-deps']), { create(context) {
6
- const originalRule = reactHooksPlugin.rules['exhaustive-deps'].create(context);
7
- return Object.assign(Object.assign({}, originalRule), { CallExpression(node) {
8
- const callbackName = node.callee.name;
9
- /** useChanged, useFirstSkipChanged */
10
- if (['useChanged', 'useFirstSkipChanged'].includes(callbackName)) {
11
- const callback = node.arguments[0];
12
- const deps = node.arguments[1];
13
- if (!deps || deps.type !== 'ArrayExpression') {
14
- context.report({
15
- node: deps || node,
16
- message: `${callbackName} 훅의 두 번째 인자는 반드시 배열 리터럴(예: [a, b]) 형태여야 합니다.`,
17
- });
18
- return;
19
- }
20
- if (callback && (callback.type === 'ArrowFunctionExpression' || callback.type === 'FunctionExpression')) {
21
- const visited = new Set();
22
- const checkRefAccess = (targetNode) => {
23
- if (!targetNode || typeof targetNode !== 'object' || visited.has(targetNode))
24
- return;
25
- visited.add(targetNode);
26
- if (targetNode.type === 'MemberExpression' &&
27
- targetNode.property &&
28
- (targetNode.property.name === 'current' ||
29
- (targetNode.property.type === 'Literal' && targetNode.property.value === 'current'))) {
30
- context.report({
31
- node: targetNode,
32
- message: `${callbackName} 훅의 콜백에서는 ref를 참조할 수 없습니다. (Cannot access refs during render.)`,
33
- });
34
- }
35
- for (const key in targetNode) {
36
- if (key === 'parent')
37
- continue;
38
- const child = targetNode[key];
39
- if (Array.isArray(child)) {
40
- child.forEach((c) => checkRefAccess(c));
41
- }
42
- else if (child && typeof child === 'object') {
43
- checkRefAccess(child);
44
- }
45
- }
46
- };
47
- checkRefAccess(callback.body);
48
- }
49
- return originalRule.CallExpression(node);
50
- }
51
- /** useEventEffect, useEventLayoutEffect */
52
- if (['useEventEffect', 'useEventLayoutEffect'].includes(callbackName)) {
53
- const deps = node.arguments[1];
54
- if (deps && deps.type !== 'ArrayExpression') {
55
- context.report({
56
- node: deps || node,
57
- message: `${callbackName} 훅의 두 번째 인자는 반드시 배열 리터럴(예: [a, b]) 형태여야 합니다.`,
58
- });
59
- return;
60
- }
61
- return originalRule.CallExpression(node);
62
- }
63
- /** useFirstSkipEffect, useFirstSkipLayoutEffect */
64
- if (['useFirstSkipEffect', 'useFirstSkipLayoutEffect'].includes(callbackName)) {
65
- const deps = node.arguments[1];
66
- if (!deps || deps.type !== 'ArrayExpression') {
67
- context.report({
68
- node: deps || node,
69
- message: `${callbackName} 훅의 두 번째 인자는 반드시 배열 리터럴(예: [a, b]) 형태여야 합니다.`,
70
- });
71
- return;
72
- }
73
- return originalRule.CallExpression(node);
74
- }
75
- return originalRule.CallExpression(node);
76
- } });
77
- } }),
78
- 'rules-of-hooks': reactHooksPlugin.rules['rules-of-hooks'],
79
- },
80
- };
81
- const plugConfig = {
82
- recommended: {
83
- plugins: ['@pdg/react-hook'],
84
- rules: {
85
- '@pdg/react-hook/rules-of-hooks': 'error',
86
- '@pdg/react-hook/exhaustive-deps': 'error',
87
- },
88
- },
89
- flat: {
90
- recommended: {
91
- plugins: {
92
- '@pdg/react-hook': pluginRules,
93
- },
94
- rules: {
95
- '@pdg/react-hook/rules-of-hooks': 'error',
96
- '@pdg/react-hook/exhaustive-deps': 'error',
97
- },
98
- },
99
- },
100
- };
101
- const plugin = {
102
- rules: pluginRules.rules,
103
- configs: plugConfig,
104
- };
105
-
106
- export { plugin as default };