@faasjs/react 0.0.4-beta.2 → 0.0.4-beta.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/dist/index.d.mts CHANGED
@@ -58,7 +58,8 @@ type useFaasOptions<PathOrData extends FaasAction> = {
58
58
  params?: FaasParams<PathOrData>
59
59
  data?: FaasData<PathOrData>
60
60
  setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
61
- skip?: boolean
61
+ /** if skip is true, will not send request */
62
+ skip?: boolean | ((params: FaasParams<PathOrData>) => boolean)
62
63
  /** send the last request after milliseconds */
63
64
  debounce?: number
64
65
  }
package/dist/index.d.ts CHANGED
@@ -58,7 +58,8 @@ type useFaasOptions<PathOrData extends FaasAction> = {
58
58
  params?: FaasParams<PathOrData>
59
59
  data?: FaasData<PathOrData>
60
60
  setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
61
- skip?: boolean
61
+ /** if skip is true, will not send request */
62
+ skip?: boolean | ((params: FaasParams<PathOrData>) => boolean)
62
63
  /** send the last request after milliseconds */
63
64
  debounce?: number
64
65
  }
package/dist/index.js CHANGED
@@ -30,17 +30,23 @@ function FaasReactClient({
30
30
  const [params, setParams] = react.useState(defaultParams);
31
31
  const [reloadTimes, setReloadTimes] = react.useState(0);
32
32
  const [fails, setFails] = react.useState(0);
33
+ const [skip, setSkip] = react.useState(
34
+ typeof options2.skip === "function" ? options2.skip(defaultParams) : options2.skip
35
+ );
33
36
  react.useEffect(
34
37
  function() {
35
38
  if (JSON.stringify(defaultParams) !== JSON.stringify(params)) {
36
39
  setParams(defaultParams);
40
+ if (typeof options2.skip === "function") {
41
+ setSkip(options2.skip(defaultParams));
42
+ }
37
43
  }
38
44
  },
39
45
  [JSON.stringify(defaultParams)]
40
46
  );
41
47
  react.useEffect(
42
48
  function() {
43
- if (!action || (options2 == null ? void 0 : options2.skip)) {
49
+ if (!action || skip) {
44
50
  setLoading(false);
45
51
  return;
46
52
  }
@@ -88,12 +94,7 @@ function FaasReactClient({
88
94
  setLoading(false);
89
95
  };
90
96
  },
91
- [
92
- action,
93
- JSON.stringify(options2.params || params),
94
- reloadTimes,
95
- options2.skip
96
- ]
97
+ [action, JSON.stringify(options2.params || params), reloadTimes, skip]
97
98
  );
98
99
  return {
99
100
  action,
package/dist/index.mjs CHANGED
@@ -28,17 +28,23 @@ function FaasReactClient({
28
28
  const [params, setParams] = useState(defaultParams);
29
29
  const [reloadTimes, setReloadTimes] = useState(0);
30
30
  const [fails, setFails] = useState(0);
31
+ const [skip, setSkip] = useState(
32
+ typeof options2.skip === "function" ? options2.skip(defaultParams) : options2.skip
33
+ );
31
34
  useEffect(
32
35
  function() {
33
36
  if (JSON.stringify(defaultParams) !== JSON.stringify(params)) {
34
37
  setParams(defaultParams);
38
+ if (typeof options2.skip === "function") {
39
+ setSkip(options2.skip(defaultParams));
40
+ }
35
41
  }
36
42
  },
37
43
  [JSON.stringify(defaultParams)]
38
44
  );
39
45
  useEffect(
40
46
  function() {
41
- if (!action || (options2 == null ? void 0 : options2.skip)) {
47
+ if (!action || skip) {
42
48
  setLoading(false);
43
49
  return;
44
50
  }
@@ -86,12 +92,7 @@ function FaasReactClient({
86
92
  setLoading(false);
87
93
  };
88
94
  },
89
- [
90
- action,
91
- JSON.stringify(options2.params || params),
92
- reloadTimes,
93
- options2.skip
94
- ]
95
+ [action, JSON.stringify(options2.params || params), reloadTimes, skip]
95
96
  );
96
97
  return {
97
98
  action,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "0.0.4-beta.2",
3
+ "version": "0.0.4-beta.3",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -23,11 +23,11 @@
23
23
  ],
24
24
  "peerDependencies": {
25
25
  "react": "*",
26
- "@faasjs/browser": "0.0.4-beta.2"
26
+ "@faasjs/browser": "0.0.4-beta.3"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/react": "*",
30
- "@faasjs/browser": "0.0.4-beta.2",
30
+ "@faasjs/browser": "0.0.4-beta.3",
31
31
  "react": "*"
32
32
  },
33
33
  "engines": {