Skip to content

Commit

Permalink
Add deprecation notice to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Jun 13, 2021
1 parent 7a5232d commit 16f8dcd
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/xstate-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ A [React hook](https://reactjs.org/hooks) that interprets the given `machine` an

### `useService(service)`

::: warning Deprecated

In the next major version, `useService(service)` will be replaced with `useActor(service)`. Prefer using the `useActor(service)` hook for services instead, since services are also actors.

:::

A [React hook](https://reactjs.org/hooks) that subscribes to state changes from an existing [service](https://xstate.js.org/docs/guides/interpretation.html).

**Arguments**
Expand All @@ -126,7 +132,7 @@ A [React hook](https://reactjs.org/hooks) that subscribes to state changes from
- `state` - Represents the current state of the service as an XState `State` object.
- `send` - A function that sends events to the running service.

### `useActor(actor, getSnapshot)`
### `useActor(actor, getSnapshot?)`

A [React hook](https://reactjs.org/hooks) that subscribes to emitted changes from an existing [actor](https://xstate.js.org/docs/guides/actors.html).

Expand Down Expand Up @@ -348,11 +354,13 @@ const fetchMachine = createMachine({
}
});

const Fetcher = ({ onFetch = () => new Promise(res => res('some data')) }) => {
const Fetcher = ({
onFetch = () => new Promise((res) => res('some data'))
}) => {
const [state, send] = useMachine(fetchMachine, {
actions: {
load: () => {
onFetch().then(res => {
onFetch().then((res) => {
send({ type: 'RESOLVE', data: res });
});
}
Expand All @@ -361,7 +369,7 @@ const Fetcher = ({ onFetch = () => new Promise(res => res('some data')) }) => {

switch (state.value) {
case 'idle':
return <button onClick={_ => send('FETCH')}>Fetch</button>;
return <button onClick={(_) => send('FETCH')}>Fetch</button>;
case 'loading':
return <div>Loading...</div>;
case 'success':
Expand Down

0 comments on commit 16f8dcd

Please sign in to comment.