@xstate/react 2.0.0-pr2674-202191175724 → 2.0.1
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/CHANGELOG.md +78 -28
- package/README.md +5 -512
- package/dist/xstate-react.umd.min.js +15 -2
- package/es/index.d.ts +0 -1
- package/es/index.js +0 -1
- package/es/useActor.js +1 -1
- package/es/useInterpret.d.ts +8 -8
- package/es/useInterpret.js +1 -1
- package/es/useMachine.d.ts +7 -7
- package/es/useMachine.js +10 -6
- package/es/useReactEffectActions.js +11 -7
- package/es/useSelector.js +52 -34
- package/es/useSpawn.js +1 -1
- package/es/utils.d.ts +2 -0
- package/es/utils.js +3 -0
- package/lib/fsm.js +8 -8
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -3
- package/lib/useActor.js +6 -6
- package/lib/useInterpret.d.ts +8 -8
- package/lib/useInterpret.js +9 -9
- package/lib/useMachine.d.ts +7 -7
- package/lib/useMachine.js +13 -9
- package/lib/useReactEffectActions.js +17 -13
- package/lib/useSelector.js +53 -35
- package/lib/useSpawn.js +3 -3
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +5 -1
- package/package.json +8 -8
- package/dist/xstate-react.cjs.js +0 -16
- package/es/useService.d.ts +0 -16
- package/es/useService.js +0 -36
- package/lib/useService.d.ts +0 -16
- package/lib/useService.js +0 -41
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,69 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 2.0.
|
|
3
|
+
## 2.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3089](https://github.com/statelyai/xstate/pull/3089) [`862697e29`](https://github.com/statelyai/xstate/commit/862697e2990934d46050580d7e09c749d09d8426) Thanks [@Andarist](https://github.com/Andarist)! - Fixed compatibility with Skypack by exporting some shared utilities from root entry of XState and consuming them directly in other packages (this avoids accessing those things using deep imports and thus it avoids creating those compatibility problems).
|
|
8
|
+
|
|
9
|
+
## 2.0.0
|
|
4
10
|
|
|
5
11
|
### Major Changes
|
|
6
12
|
|
|
7
|
-
- e5a8b8dff
|
|
8
|
-
|
|
13
|
+
- [#2674](https://github.com/statelyai/xstate/pull/2674) [`e5a8b8dff`](https://github.com/statelyai/xstate/commit/e5a8b8dffb88cffbdca26683099ffdf5f1b01c8d) Thanks [@Andarist](https://github.com/Andarist), [@mattpocock](https://github.com/mattpocock)! - To avoid breaking any consumers and to leverage the newly introduced typegen support, the major version of this package had to be bumped. While you can still use it with older versions of TS, the typegen support in this package requires TS version 4.0 or greater.
|
|
14
|
+
|
|
15
|
+
When using hooks from `@xstate/react` it's recommended to skip providing explicit generics to them. Note that that generics list has changed since v1 and we now only accept a single generic, `TMachine`.
|
|
16
|
+
|
|
17
|
+
* [#2674](https://github.com/statelyai/xstate/pull/2674) [`ab919d300`](https://github.com/statelyai/xstate/commit/ab919d300f6d2b78871d3399ec58a697c4268d9b) Thanks [@Andarist](https://github.com/Andarist)! - Removed already deprecated `useService` from `@xstate/react`. You can replace its usage with `useActor`.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- [#2957](https://github.com/statelyai/xstate/pull/2957) [`8550ddda7`](https://github.com/statelyai/xstate/commit/8550ddda73e2ad291e19173d7fa8d13e3336fbb9) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The repository links have been updated from `github.com/davidkpiano` to `github.com/statelyai`.
|
|
9
22
|
|
|
10
|
-
|
|
23
|
+
## 1.6.3
|
|
11
24
|
|
|
12
25
|
### Patch Changes
|
|
13
26
|
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
27
|
+
- [#2767](https://github.com/statelyai/xstate/pull/2767) [`c1503b121`](https://github.com/statelyai/xstate/commit/c1503b1219d995ebf0f45de46036c5a1d7e6442f) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an over-rendering issue in the `useSelector`.
|
|
28
|
+
|
|
29
|
+
## 1.6.2
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- [#2736](https://github.com/statelyai/xstate/pull/2736) [`2246ae051`](https://github.com/statelyai/xstate/commit/2246ae051663f261b4750d7adba57f008ec28f1d) Thanks [@Andarist](https://github.com/Andarist), [@davidkpiano](https://github.com/statelyai), [@VanTanev](https://github.com/VanTanev)! - The `useSelector(...)` hook now works as expected when the `actor` passed in changes. The hook will properly subscribe to the new `actor` and select the desired value. See [#2702](https://github.com/statelyai/xstate/issues/2702)
|
|
34
|
+
|
|
35
|
+
* [#2685](https://github.com/statelyai/xstate/pull/2685) [`469268d39`](https://github.com/statelyai/xstate/commit/469268d39fbc23996599773adfc4ca824b48585f) Thanks [@farskid](https://github.com/farskid), [@Andarist](https://github.com/Andarist)! - Fixed a regression with a development-only warning not being shown when a machine reference is updated during the hook lifecycle. This usually happens when machine options are dependent on external values and they're passed via `withConfig`.
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
const machine = createMachine({
|
|
39
|
+
initial: 'foo',
|
|
40
|
+
context: { id: 1 },
|
|
41
|
+
states: {
|
|
42
|
+
foo: {
|
|
43
|
+
on: {
|
|
44
|
+
CHECK: {
|
|
45
|
+
target: 'bar',
|
|
46
|
+
cond: 'hasOverflown'
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
bar: {}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const [id, setId] = useState(1);
|
|
55
|
+
const [current, send] = useMachine(
|
|
56
|
+
machine.withConfig({
|
|
57
|
+
guards: {
|
|
58
|
+
hasOverflown: () => id > 1 // id is a reference to an outside value
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// later when id updates
|
|
64
|
+
setId(2);
|
|
65
|
+
// Now the reference passed to `useMachine` (the result of `machine.withConfig`) is updated but the interpreted machine stays the same. So the guard is still the previous one that got passed to the `useMachine` initially, and it closes over the stale `id`.
|
|
66
|
+
```
|
|
17
67
|
|
|
18
68
|
## 1.6.1
|
|
19
69
|
|
|
@@ -76,13 +126,13 @@
|
|
|
76
126
|
|
|
77
127
|
### Patch Changes
|
|
78
128
|
|
|
79
|
-
- [`453acacb`](https://github.com/statelyai/xstate/commit/453acacbec364531a2851f183c3ab446d7db0e84) [#2389](https://github.com/statelyai/xstate/pull/2389) Thanks [@davidkpiano](https://github.com/
|
|
129
|
+
- [`453acacb`](https://github.com/statelyai/xstate/commit/453acacbec364531a2851f183c3ab446d7db0e84) [#2389](https://github.com/statelyai/xstate/pull/2389) Thanks [@davidkpiano](https://github.com/statelyai)! - An internal issue where the `spawnBehavior` import for the `useSpawn(...)` hook was broken internally has been fixed.
|
|
80
130
|
|
|
81
131
|
## 1.5.0
|
|
82
132
|
|
|
83
133
|
### Minor Changes
|
|
84
134
|
|
|
85
|
-
- [`432b60f7`](https://github.com/statelyai/xstate/commit/432b60f7bcbcee9510e0d86311abbfd75b1a674e) [#2280](https://github.com/statelyai/xstate/pull/2280) Thanks [@davidkpiano](https://github.com/
|
|
135
|
+
- [`432b60f7`](https://github.com/statelyai/xstate/commit/432b60f7bcbcee9510e0d86311abbfd75b1a674e) [#2280](https://github.com/statelyai/xstate/pull/2280) Thanks [@davidkpiano](https://github.com/statelyai)! - Just like `useInvoke(...)`, other types of actors can now be spawned from _behaviors_ using `useSpawn(...)`:
|
|
86
136
|
|
|
87
137
|
```tsx
|
|
88
138
|
import { fromReducer } from 'xstate/lib/behaviors';
|
|
@@ -136,7 +186,7 @@
|
|
|
136
186
|
|
|
137
187
|
### Minor Changes
|
|
138
188
|
|
|
139
|
-
- [`849ec56c`](https://github.com/
|
|
189
|
+
- [`849ec56c`](https://github.com/statelyai/xstate/commit/849ec56c2a9db34e65a30af94e68a7a7a50b4158) [#2286](https://github.com/statelyai/xstate/pull/2286) Thanks [@davidkpiano](https://github.com/statelyai)! - The `useService(...)` hook will be deprecated, since services are also actors. In future versions, the `useActor(...)` hook should be used instead:
|
|
140
190
|
|
|
141
191
|
```diff
|
|
142
192
|
-const [state, send] = useService(service);
|
|
@@ -145,25 +195,25 @@
|
|
|
145
195
|
|
|
146
196
|
### Patch Changes
|
|
147
197
|
|
|
148
|
-
- [`ea3aaffb`](https://github.com/
|
|
198
|
+
- [`ea3aaffb`](https://github.com/statelyai/xstate/commit/ea3aaffb906b34a42bb2736c7b91d54ffe9ed882) [#2326](https://github.com/statelyai/xstate/pull/2326) Thanks [@davidkpiano](https://github.com/statelyai)! - The `send` type returned in the tuple from `useActor(someService)` was an incorrect `never` type; this has been fixed.
|
|
149
199
|
|
|
150
200
|
## 1.3.4
|
|
151
201
|
|
|
152
202
|
### Patch Changes
|
|
153
203
|
|
|
154
|
-
- [`aa3c2991`](https://github.com/
|
|
204
|
+
- [`aa3c2991`](https://github.com/statelyai/xstate/commit/aa3c29916b7382fbcf1a3efb183ca1e8eb625480) [#2223](https://github.com/statelyai/xstate/pull/2223) Thanks [@davidkpiano](https://github.com/statelyai)! - Support for actor refs with the `.getSnapshot()` method (added for spawned actors in XState version 4.19) is now supported in the `useActor(...)` hook.
|
|
155
205
|
|
|
156
206
|
## 1.3.3
|
|
157
207
|
|
|
158
208
|
### Patch Changes
|
|
159
209
|
|
|
160
|
-
- [`27e7242c`](https://github.com/
|
|
210
|
+
- [`27e7242c`](https://github.com/statelyai/xstate/commit/27e7242c24146de85cf618a658b400a3241fa7d7) [#2112](https://github.com/statelyai/xstate/pull/2112) Thanks [@davidkpiano](https://github.com/statelyai)! - The `executeEffect` function is no longer exported (was meant to be internal and is useless as a public function anyway). This also fixes a circular dependency issue.
|
|
161
211
|
|
|
162
212
|
## 1.3.2
|
|
163
213
|
|
|
164
214
|
### Patch Changes
|
|
165
215
|
|
|
166
|
-
- [`bb5e81ea`](https://github.com/
|
|
216
|
+
- [`bb5e81ea`](https://github.com/statelyai/xstate/commit/bb5e81eaa1ecba1fd54a7677ce9eaee9bd695964) [#2050](https://github.com/statelyai/xstate/pull/2050) Thanks [@theKashey](https://github.com/theKashey)! - Added an explicit entrypoint for `@xstate/react/fsm` which you can use instead of `@xstate/react/lib/fsm`. This is the only specifier that will be supported in the future - the other one will be dropped in the next major version.
|
|
167
217
|
|
|
168
218
|
```diff
|
|
169
219
|
-import { useMachine } from '@xstate/react/lib/fsm'
|
|
@@ -174,15 +224,15 @@
|
|
|
174
224
|
|
|
175
225
|
### Patch Changes
|
|
176
226
|
|
|
177
|
-
- [`b076b253`](https://github.com/
|
|
227
|
+
- [`b076b253`](https://github.com/statelyai/xstate/commit/b076b25364224874f62e8065892be40dfbb28030) [#1947](https://github.com/statelyai/xstate/pull/1947) Thanks [@lukekarrys](https://github.com/lukekarrys)! - Fix typing of the service returned from the fsm useMachine hook by passing it Typestate
|
|
178
228
|
|
|
179
|
-
* [`9b5dc784`](https://github.com/
|
|
229
|
+
* [`9b5dc784`](https://github.com/statelyai/xstate/commit/9b5dc7843c44f50bcca0ffccb843b3d50cef6ddc) [#1950](https://github.com/statelyai/xstate/pull/1950) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with `toObserver` being internally imported from `xstate/lib/utils` which has broken UMD build and the declared peer dep contract.
|
|
180
230
|
|
|
181
231
|
## 1.3.0
|
|
182
232
|
|
|
183
233
|
### Minor Changes
|
|
184
234
|
|
|
185
|
-
- [`577ae023`](https://github.com/
|
|
235
|
+
- [`577ae023`](https://github.com/statelyai/xstate/commit/577ae02384926b49e876011c4393f212b49066f8) [#1915](https://github.com/statelyai/xstate/pull/1915) Thanks [@davidkpiano](https://github.com/statelyai)! - New hook: `useInterpret(machine)`, which is a low-level hook that interprets the `machine` and returns the `service`:
|
|
186
236
|
|
|
187
237
|
```js
|
|
188
238
|
import { useInterpret } from '@xstate/react';
|
|
@@ -195,7 +245,7 @@
|
|
|
195
245
|
};
|
|
196
246
|
```
|
|
197
247
|
|
|
198
|
-
* [`577ae023`](https://github.com/
|
|
248
|
+
* [`577ae023`](https://github.com/statelyai/xstate/commit/577ae02384926b49e876011c4393f212b49066f8) [#1915](https://github.com/statelyai/xstate/pull/1915) Thanks [@davidkpiano](https://github.com/statelyai)! - New hook: `useSelector(actor, selector)`, which subscribes to `actor` and returns the selected state derived from `selector(snapshot)`:
|
|
199
249
|
|
|
200
250
|
```js
|
|
201
251
|
import { useSelector } from '@xstate/react';
|
|
@@ -211,25 +261,25 @@
|
|
|
211
261
|
|
|
212
262
|
### Patch Changes
|
|
213
263
|
|
|
214
|
-
- [`4b31cefb`](https://github.com/
|
|
264
|
+
- [`4b31cefb`](https://github.com/statelyai/xstate/commit/4b31cefb3d3497e5515314046639df7e27dbe9e8) [#1780](https://github.com/statelyai/xstate/pull/1780) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with some external packages not being bundled correctly into the UMD bundles.
|
|
215
265
|
|
|
216
266
|
## 1.2.1
|
|
217
267
|
|
|
218
268
|
### Patch Changes
|
|
219
269
|
|
|
220
|
-
- [`a16a5f2f`](https://github.com/
|
|
270
|
+
- [`a16a5f2f`](https://github.com/statelyai/xstate/commit/a16a5f2ff5ba9d4d7834ec3ca2d0adecf5d6a870) [#1756](https://github.com/statelyai/xstate/pull/1756) Thanks [@dimitardanailov](https://github.com/dimitardanailov)! - Fixed an issue with `process` references not being removed correctly from the UMD bundles.
|
|
221
271
|
|
|
222
272
|
## 1.2.0
|
|
223
273
|
|
|
224
274
|
### Minor Changes
|
|
225
275
|
|
|
226
|
-
- [`dd98296e`](https://github.com/
|
|
276
|
+
- [`dd98296e`](https://github.com/statelyai/xstate/commit/dd98296e9fcbae905da2395e67e876e28be7c774) [#1738](https://github.com/statelyai/xstate/pull/1738) Thanks [@dimitardanailov](https://github.com/dimitardanailov)! - Added UMD bundle.
|
|
227
277
|
|
|
228
278
|
## 1.1.0
|
|
229
279
|
|
|
230
280
|
### Minor Changes
|
|
231
281
|
|
|
232
|
-
- [`89f9c27c`](https://github.com/
|
|
282
|
+
- [`89f9c27c`](https://github.com/statelyai/xstate/commit/89f9c27c453dc56bdfdf49c8ea1f0f87ff1f9b67) [#1622](https://github.com/statelyai/xstate/pull/1622) Thanks [@davidkpiano](https://github.com/statelyai)! - Spawned/invoked actors and interpreters are now typed as extending `ActorRef` rather than `Actor` or `Interpreter`. This unification of types should make it more straightforward to provide actor types in React:
|
|
233
283
|
|
|
234
284
|
```ts
|
|
235
285
|
import { ActorRef } from 'xstate';
|
|
@@ -271,15 +321,15 @@
|
|
|
271
321
|
|
|
272
322
|
### Patch Changes
|
|
273
323
|
|
|
274
|
-
- [`27db2950`](https://github.com/
|
|
324
|
+
- [`27db2950`](https://github.com/statelyai/xstate/commit/27db295064d42cacb89ff10d55f39eb7609148e1) [#1636](https://github.com/statelyai/xstate/pull/1636) Thanks [@Andarist](https://github.com/Andarist)! - Allow React 17 in the specified peer dependency range.
|
|
275
325
|
|
|
276
326
|
## 1.0.2
|
|
277
327
|
|
|
278
328
|
### Patch Changes
|
|
279
329
|
|
|
280
|
-
- [`c7927083`](https://github.com/
|
|
330
|
+
- [`c7927083`](https://github.com/statelyai/xstate/commit/c7927083a651e3c51952ade2ffda793df0391bf6) [#1516](https://github.com/statelyai/xstate/pull/1516) Thanks [@davidkpiano](https://github.com/statelyai)! - The `send` function returned from the `useService()` now can take two arguments (an event type and payload), to match the behavior of `@xstate/react` version 0.x.
|
|
281
331
|
|
|
282
|
-
* [`db77623a`](https://github.com/
|
|
332
|
+
* [`db77623a`](https://github.com/statelyai/xstate/commit/db77623a48955d762cffa9b624f438220add5eed) [#1516](https://github.com/statelyai/xstate/pull/1516) Thanks [@davidkpiano](https://github.com/statelyai)! - The `send` value returned from the `useService()` hook will now accept a payload, which matches the signature of the `send` value returned from the `useMachine()` hook:
|
|
283
333
|
|
|
284
334
|
```js
|
|
285
335
|
const [state, send] = useService(someService);
|
|
@@ -293,15 +343,15 @@
|
|
|
293
343
|
send({ type: 'ADD', value: 3 });
|
|
294
344
|
```
|
|
295
345
|
|
|
296
|
-
- [`93f6db02`](https://github.com/
|
|
346
|
+
- [`93f6db02`](https://github.com/statelyai/xstate/commit/93f6db02a2d56ec997198ddef0af3d7730bb79bb) [#1594](https://github.com/statelyai/xstate/pull/1594) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with internal `setState` in `useService` being called with 2 arguments instead of 1.
|
|
297
347
|
|
|
298
|
-
* [`72b0880e`](https://github.com/
|
|
348
|
+
* [`72b0880e`](https://github.com/statelyai/xstate/commit/72b0880e6444ae009adca72088872bb5c0760ce3) [#1504](https://github.com/statelyai/xstate/pull/1504) Thanks [@Andarist](https://github.com/Andarist)! - Fixed issue with `useService` returning an initial state for services in their final states.
|
|
299
349
|
|
|
300
350
|
## 1.0.1
|
|
301
351
|
|
|
302
352
|
### Patch Changes
|
|
303
353
|
|
|
304
|
-
- [`c0bd0407`](https://github.com/
|
|
354
|
+
- [`c0bd0407`](https://github.com/statelyai/xstate/commit/c0bd040767dcac20ed690e49a8725b4f1011dd5d) [#1493](https://github.com/statelyai/xstate/pull/1493) Thanks [@davidkpiano](https://github.com/statelyai)! - There will now be a descriptive error when trying to use an actor-like object in the `useService()` hook, where `useActor()` should be preferred:
|
|
305
355
|
|
|
306
356
|
> Attempted to use an actor-like object instead of a service in the useService() hook. Please use the useActor() hook instead.
|
|
307
357
|
|