Skip to content
This repository has been archived by the owner on May 24, 2020. It is now read-only.

Router state-machine hook, powered by XState (DEPRECATED).

License

Notifications You must be signed in to change notification settings

carloslfu/use-router-machine

Repository files navigation

use-router-machine

⚠️ DEPRECATED, use useRouterMachine from xstate-router instead.

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.

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>
}

About

Router state-machine hook, powered by XState (DEPRECATED).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published