# use-router-machine

> Hook that let's you use XState as a router.

Latest version **0.2.1** (published 2020-05-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-router-machine
pnpm add use-router-machine
yarn add use-router-machine
bun add use-router-machine
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2020-05-13 |
| First published | 2018-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | @carloslfu |
| Maintainers | carloslfu |
| Keywords | xstate, react, router, react-hook, statecharts, state-machines, javascript |

## Links

- npm: https://www.npmjs.com/package/use-router-machine
- Repository: https://github.com/carloslfu/xstate-react-router
- Homepage: https://github.com/carloslfu/xstate-react-router#readme
- Issues: https://github.com/carloslfu/xstate-react-router/issues
- npm.io page: https://npm.io/package/use-router-machine

## Dependencies (2)

- [history](https://npm.io/package/history.md) ^4.10.1
- [xstate-router](https://npm.io/package/xstate-router.md) ^0.4.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2020-05-13
- 0.2.0 — 2020-02-12
- 0.1.1 — 2019-06-04
- 0.1.0 — 2018-11-26

## README

# use-router-machine

Hook that let's you use XState as a router, by using the `meta` property.

Live example: https://codesandbox.io/s/8n06pwy61l

## Use

Install the library with `npm i use-router-machine`.

```javascript
import { useRouterMachine } from 'use-router-machine'

const config = {
  initial: 'home',
  states: {
    home: { meta: { path: '/' }, on: { NEXT: 'about' } },
    about: { meta: { path: '/about' }, on: { NEXT: 'dashboard' } },
    dashboard: {
      meta: { path: '/dashboard' },
      initial: 'login',
      on: { NEXT: 'home' },
      states: {
        loggedIn: {
          initial: 'main',
          states: {
            main: { meta: { path: '/dashboard/main' } },
            data: { meta: { path: '/dashboard/data' } }
          }
        },
        login: {
          meta: { path: '/dashboard/login' },
          on: { LoggedIn: 'loggedIn' }
        }
      }
    }
  }
}

function App() {
    const service = useRouterMachine({ config })

    return <div>{service.state.value}</div>
}
```

---
_Source: https://npm.io/package/use-router-machine · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
