@use-voltra/core 2.3.0 → 2.3.2
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/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/useUpdateOnHMR.js +23 -0
- package/build/cjs/useUpdateOnHMR.js.map +1 -0
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/useUpdateOnHMR.js +19 -0
- package/build/esm/useUpdateOnHMR.js.map +1 -0
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/types.d.ts +81 -0
- package/build/types/types.d.ts.map +1 -1
- package/build/types/useUpdateOnHMR.d.ts +7 -0
- package/build/types/useUpdateOnHMR.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/types.ts +96 -0
- package/src/useUpdateOnHMR.ts +24 -0
package/build/cjs/index.js
CHANGED
|
@@ -20,5 +20,6 @@ __exportStar(require("./payload.js"), exports);
|
|
|
20
20
|
__exportStar(require("./payload/short-names.js"), exports);
|
|
21
21
|
__exportStar(require("./renderer/index.js"), exports);
|
|
22
22
|
__exportStar(require("./types.js"), exports);
|
|
23
|
+
__exportStar(require("./useUpdateOnHMR.js"), exports);
|
|
23
24
|
__exportStar(require("./widget-environment.js"), exports);
|
|
24
25
|
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAmC;AACnC,iEAA8C;AAC9C,+CAA4B;AAC5B,2DAAwC;AACxC,sDAAmC;AACnC,6CAA0B;AAC1B,0DAAuC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAmC;AACnC,iEAA8C;AAC9C,+CAA4B;AAC5B,2DAAwC;AACxC,sDAAmC;AACnC,6CAA0B;AAC1B,sDAAmC;AACnC,0DAAuC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useUpdateOnHMR = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const fastRefreshHub_js_1 = require("./fastRefreshHub.js");
|
|
6
|
+
/**
|
|
7
|
+
* Force the calling component to re-render whenever Metro applies a Fast Refresh
|
|
8
|
+
* patch, so freshly patched Voltra payloads are re-rendered. Shared by the iOS and
|
|
9
|
+
* Android client packages; relies on the process-wide {@link FastRefreshHub}.
|
|
10
|
+
*/
|
|
11
|
+
const useUpdateOnHMR = () => {
|
|
12
|
+
const [, forceUpdate] = (0, react_1.useState)(0);
|
|
13
|
+
(0, react_1.useEffect)(() => {
|
|
14
|
+
if (!__DEV__) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
return (0, fastRefreshHub_js_1.getFastRefreshHub)().onPatch(() => {
|
|
18
|
+
forceUpdate((prev) => prev + 1);
|
|
19
|
+
});
|
|
20
|
+
}, []);
|
|
21
|
+
};
|
|
22
|
+
exports.useUpdateOnHMR = useUpdateOnHMR;
|
|
23
|
+
//# sourceMappingURL=useUpdateOnHMR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUpdateOnHMR.js","sourceRoot":"","sources":["../../src/useUpdateOnHMR.ts"],"names":[],"mappings":";;;AAAA,iCAA2C;AAE3C,2DAAuD;AAIvD;;;;GAIG;AACI,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAAC,CAAC,CAAC,CAAA;IAEnC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAM;QACR,CAAC;QAED,OAAO,IAAA,qCAAiB,GAAE,CAAC,OAAO,CAAC,GAAG,EAAE;YACtC,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAA;QACjC,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA;AAZY,QAAA,cAAc,kBAY1B"}
|
package/build/esm/index.js
CHANGED
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,cAAc,CAAA;AAC5B,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA;AAC1B,cAAc,yBAAyB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,cAAc,CAAA;AAC5B,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA;AAC1B,cAAc,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { getFastRefreshHub } from './fastRefreshHub.js';
|
|
3
|
+
/**
|
|
4
|
+
* Force the calling component to re-render whenever Metro applies a Fast Refresh
|
|
5
|
+
* patch, so freshly patched Voltra payloads are re-rendered. Shared by the iOS and
|
|
6
|
+
* Android client packages; relies on the process-wide {@link FastRefreshHub}.
|
|
7
|
+
*/
|
|
8
|
+
export const useUpdateOnHMR = () => {
|
|
9
|
+
const [, forceUpdate] = useState(0);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!__DEV__) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
return getFastRefreshHub().onPatch(() => {
|
|
15
|
+
forceUpdate((prev) => prev + 1);
|
|
16
|
+
});
|
|
17
|
+
}, []);
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=useUpdateOnHMR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUpdateOnHMR.js","sourceRoot":"","sources":["../../src/useUpdateOnHMR.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAIvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAEnC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAM;QACR,CAAC;QAED,OAAO,iBAAiB,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE;YACtC,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAA;QACjC,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA"}
|
package/build/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,cAAc,CAAA;AAC5B,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA;AAC1B,cAAc,yBAAyB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,cAAc,CAAA;AAC5B,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA;AAC1B,cAAc,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA"}
|
package/build/types/types.d.ts
CHANGED
|
@@ -9,4 +9,85 @@ export type VoltraElementRef = {
|
|
|
9
9
|
$r: number;
|
|
10
10
|
};
|
|
11
11
|
export type VoltraNodeJson = VoltraElementJson | VoltraElementJson[] | VoltraElementRef | string;
|
|
12
|
+
export type EventSubscription = {
|
|
13
|
+
remove: () => void;
|
|
14
|
+
};
|
|
15
|
+
type PreloadImageBaseOptions = {
|
|
16
|
+
key: string;
|
|
17
|
+
width?: number;
|
|
18
|
+
height?: number;
|
|
19
|
+
};
|
|
20
|
+
export type PreloadImageUrlOptions = PreloadImageBaseOptions & {
|
|
21
|
+
url: string;
|
|
22
|
+
method?: 'GET' | 'POST' | 'PUT';
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
};
|
|
25
|
+
export type PreloadImageSvgOptions = PreloadImageBaseOptions & {
|
|
26
|
+
svg: string;
|
|
27
|
+
};
|
|
28
|
+
export type PreloadImageOptions = PreloadImageUrlOptions | PreloadImageSvgOptions;
|
|
29
|
+
export type PreloadImageFailure = {
|
|
30
|
+
key: string;
|
|
31
|
+
error: string;
|
|
32
|
+
};
|
|
33
|
+
export type PreloadImagesResult = {
|
|
34
|
+
succeeded: string[];
|
|
35
|
+
failed: PreloadImageFailure[];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated Use `setWidgetServerUpdate` with an `Authorization` header instead. These are
|
|
39
|
+
* stored in the same place and keep the same replace-the-whole-set semantics.
|
|
40
|
+
*/
|
|
41
|
+
export type WidgetServerCredentials = {
|
|
42
|
+
token: string;
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Runtime overrides for a widget's `serverUpdate` settings — the twin of the `serverUpdate` key
|
|
47
|
+
* in app.json, which supplies the defaults.
|
|
48
|
+
*
|
|
49
|
+
* Every field is optional and replaces the app.json value when set. `headers` and `query` merge
|
|
50
|
+
* per key across layers; everything else takes the value from the most specific layer that sets
|
|
51
|
+
* it. Passing settings without a `widgetId` sets them for every server-driven widget.
|
|
52
|
+
*/
|
|
53
|
+
export type WidgetServerUpdateSettings = {
|
|
54
|
+
/** Endpoint to fetch from. Must be https, or http to a local dev host in a debug build. */
|
|
55
|
+
url?: string;
|
|
56
|
+
/** How often to fetch, in minutes. Clamped to at least 15 and at most 24 hours. */
|
|
57
|
+
intervalMinutes?: number;
|
|
58
|
+
/** Set false to stop fetching and drive the widget from the app instead. Defaults to true. */
|
|
59
|
+
enabled?: boolean;
|
|
60
|
+
/** HTTP method. Defaults to GET. A body is dropped on GET and HEAD, with a warning. */
|
|
61
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
62
|
+
/** Extra query parameters. Voltra's own keys are reserved and rejected. */
|
|
63
|
+
query?: Record<string, string>;
|
|
64
|
+
/** Extra request headers, for example `Authorization`. */
|
|
65
|
+
headers?: Record<string, string>;
|
|
66
|
+
/** Request body, sent as `application/json`. */
|
|
67
|
+
body?: WidgetServerUpdateBody;
|
|
68
|
+
};
|
|
69
|
+
/** A JSON value, as accepted for a server-update request body. */
|
|
70
|
+
export type WidgetServerUpdateBody = string | number | boolean | null | WidgetServerUpdateBody[] | {
|
|
71
|
+
[key: string]: WidgetServerUpdateBody;
|
|
72
|
+
};
|
|
73
|
+
/** Options selecting which widget a settings call applies to. */
|
|
74
|
+
export type WidgetServerUpdateOptions = {
|
|
75
|
+
/** Widget id to scope the settings to. Omit to set them for every server-driven widget. */
|
|
76
|
+
widgetId?: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Fully resolved settings for one widget: every layer flattened and app.json's defaults applied,
|
|
80
|
+
* exactly what it would fetch with right now.
|
|
81
|
+
*/
|
|
82
|
+
export type WidgetServerUpdateSnapshot = {
|
|
83
|
+
/** Absent when the widget is server-driven but has no URL yet. */
|
|
84
|
+
url?: string;
|
|
85
|
+
intervalMinutes: number;
|
|
86
|
+
enabled: boolean;
|
|
87
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
88
|
+
query: Record<string, string>;
|
|
89
|
+
headers: Record<string, string>;
|
|
90
|
+
body?: WidgetServerUpdateBody;
|
|
91
|
+
};
|
|
92
|
+
export {};
|
|
12
93
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,cAAc,CAAA;AAE/E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,CAAC,EAAE,MAAM,CAAA;IACV,CAAC,CAAC,EAAE,cAAc,CAAA;IAClB,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CACpC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,iBAAiB,GAAG,iBAAiB,EAAE,GAAG,gBAAgB,GAAG,MAAM,CAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,cAAc,CAAA;AAE/E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,CAAC,EAAE,MAAM,CAAA;I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A"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Force the calling component to re-render whenever Metro applies a Fast Refresh
|
|
3
|
+
* patch, so freshly patched Voltra payloads are re-rendered. Shared by the iOS and
|
|
4
|
+
* Android client packages; relies on the process-wide {@link FastRefreshHub}.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useUpdateOnHMR: () => void;
|
|
7
|
+
//# sourceMappingURL=useUpdateOnHMR.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUpdateOnHMR.d.ts","sourceRoot":"","sources":["../../src/useUpdateOnHMR.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,eAAO,MAAM,cAAc,YAY1B,CAAA"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -12,3 +12,99 @@ export type VoltraElementRef = {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export type VoltraNodeJson = VoltraElementJson | VoltraElementJson[] | VoltraElementRef | string
|
|
15
|
+
|
|
16
|
+
export type EventSubscription = {
|
|
17
|
+
remove: () => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type PreloadImageBaseOptions = {
|
|
21
|
+
key: string
|
|
22
|
+
width?: number
|
|
23
|
+
height?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type PreloadImageUrlOptions = PreloadImageBaseOptions & {
|
|
27
|
+
url: string
|
|
28
|
+
method?: 'GET' | 'POST' | 'PUT'
|
|
29
|
+
headers?: Record<string, string>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type PreloadImageSvgOptions = PreloadImageBaseOptions & {
|
|
33
|
+
svg: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type PreloadImageOptions = PreloadImageUrlOptions | PreloadImageSvgOptions
|
|
37
|
+
|
|
38
|
+
export type PreloadImageFailure = {
|
|
39
|
+
key: string
|
|
40
|
+
error: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type PreloadImagesResult = {
|
|
44
|
+
succeeded: string[]
|
|
45
|
+
failed: PreloadImageFailure[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use `setWidgetServerUpdate` with an `Authorization` header instead. These are
|
|
50
|
+
* stored in the same place and keep the same replace-the-whole-set semantics.
|
|
51
|
+
*/
|
|
52
|
+
export type WidgetServerCredentials = {
|
|
53
|
+
token: string
|
|
54
|
+
headers?: Record<string, string>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Runtime overrides for a widget's `serverUpdate` settings — the twin of the `serverUpdate` key
|
|
59
|
+
* in app.json, which supplies the defaults.
|
|
60
|
+
*
|
|
61
|
+
* Every field is optional and replaces the app.json value when set. `headers` and `query` merge
|
|
62
|
+
* per key across layers; everything else takes the value from the most specific layer that sets
|
|
63
|
+
* it. Passing settings without a `widgetId` sets them for every server-driven widget.
|
|
64
|
+
*/
|
|
65
|
+
export type WidgetServerUpdateSettings = {
|
|
66
|
+
/** Endpoint to fetch from. Must be https, or http to a local dev host in a debug build. */
|
|
67
|
+
url?: string
|
|
68
|
+
/** How often to fetch, in minutes. Clamped to at least 15 and at most 24 hours. */
|
|
69
|
+
intervalMinutes?: number
|
|
70
|
+
/** Set false to stop fetching and drive the widget from the app instead. Defaults to true. */
|
|
71
|
+
enabled?: boolean
|
|
72
|
+
/** HTTP method. Defaults to GET. A body is dropped on GET and HEAD, with a warning. */
|
|
73
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
|
|
74
|
+
/** Extra query parameters. Voltra's own keys are reserved and rejected. */
|
|
75
|
+
query?: Record<string, string>
|
|
76
|
+
/** Extra request headers, for example `Authorization`. */
|
|
77
|
+
headers?: Record<string, string>
|
|
78
|
+
/** Request body, sent as `application/json`. */
|
|
79
|
+
body?: WidgetServerUpdateBody
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A JSON value, as accepted for a server-update request body. */
|
|
83
|
+
export type WidgetServerUpdateBody =
|
|
84
|
+
| string
|
|
85
|
+
| number
|
|
86
|
+
| boolean
|
|
87
|
+
| null
|
|
88
|
+
| WidgetServerUpdateBody[]
|
|
89
|
+
| { [key: string]: WidgetServerUpdateBody }
|
|
90
|
+
|
|
91
|
+
/** Options selecting which widget a settings call applies to. */
|
|
92
|
+
export type WidgetServerUpdateOptions = {
|
|
93
|
+
/** Widget id to scope the settings to. Omit to set them for every server-driven widget. */
|
|
94
|
+
widgetId?: string
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Fully resolved settings for one widget: every layer flattened and app.json's defaults applied,
|
|
99
|
+
* exactly what it would fetch with right now.
|
|
100
|
+
*/
|
|
101
|
+
export type WidgetServerUpdateSnapshot = {
|
|
102
|
+
/** Absent when the widget is server-driven but has no URL yet. */
|
|
103
|
+
url?: string
|
|
104
|
+
intervalMinutes: number
|
|
105
|
+
enabled: boolean
|
|
106
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
|
|
107
|
+
query: Record<string, string>
|
|
108
|
+
headers: Record<string, string>
|
|
109
|
+
body?: WidgetServerUpdateBody
|
|
110
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { getFastRefreshHub } from './fastRefreshHub.js'
|
|
4
|
+
|
|
5
|
+
declare const __DEV__: boolean | undefined
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Force the calling component to re-render whenever Metro applies a Fast Refresh
|
|
9
|
+
* patch, so freshly patched Voltra payloads are re-rendered. Shared by the iOS and
|
|
10
|
+
* Android client packages; relies on the process-wide {@link FastRefreshHub}.
|
|
11
|
+
*/
|
|
12
|
+
export const useUpdateOnHMR = () => {
|
|
13
|
+
const [, forceUpdate] = useState(0)
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!__DEV__) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return getFastRefreshHub().onPatch(() => {
|
|
21
|
+
forceUpdate((prev) => prev + 1)
|
|
22
|
+
})
|
|
23
|
+
}, [])
|
|
24
|
+
}
|