You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/api/hot-module-replacement.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@ if (module.hot) {
23
23
24
24
The following methods are supported...
25
25
26
+
## Module API
26
27
27
28
### `accept`
28
29
@@ -35,6 +36,23 @@ module.hot.accept(
35
36
)
36
37
```
37
38
39
+
When using ESM `import` all imported symbols from `dependencies` are automatically updated. Note: The dependency string must match exactly with the `from` string in the `import`. In some cases `callback` can even be omitted. Using `require()` in the `callback` doesn't make sense here.
40
+
41
+
When using CommonJS you need to update dependencies manually by using `require()` in the `callback`. Omitting the `callback` doesn't make sense here.
42
+
43
+
### `accept` (self)
44
+
45
+
Accept updates for itself.
46
+
47
+
```js
48
+
module.hot.accept(
49
+
errorHandler // Function to handle errors when evaluating the new version
50
+
)
51
+
```
52
+
53
+
When this module or dependencies are updated, this module can be disposed and re-evaluated without informing parents. This makes sense if this module has no exports (or exports are updated in another way).
54
+
55
+
The `errorHandler` is fired when the evaluation of this module (or dependencies) has thrown an exception.
38
56
39
57
### `decline`
40
58
@@ -46,6 +64,17 @@ module.hot.decline(
46
64
)
47
65
```
48
66
67
+
Flag a dependency as not-update-able. This makes sense when changing exports of this dependency can be handled or handling is not implemented yet. Depending on your HMR management code an update to this dependencies (or unaccepted dependencies of it) usually causes a full-reload of the page.
68
+
69
+
### `decline` (self)
70
+
71
+
Reject updates for itself.
72
+
73
+
```js
74
+
module.hot.decline()
75
+
```
76
+
77
+
Flag this module as not-update-able. This make sense when this module has inrevertable side-effects, or HMR handling is not implemented for this module yet. Depending on your HMR management code an update to this module (or unaccepted dependencies) usually causes a full-reload of the page.
49
78
50
79
### `dispose` (or `addDisposeHandler`)
51
80
@@ -66,6 +95,7 @@ Remove the callback added via `dispose` or `addDisposeHandler`.
0 commit comments