0.8.0 • Published 2 years ago

@routo/react v0.8.0

Weekly downloads
15
License
MIT
Repository
github
Last release
2 years ago

routo

@routo/react

npm npm bundle size coverage license

React bindings package for @routo/core

Install

yarn add @routo/core @routo/react

Usage

import { createRouter, NOT_FOUND } from '@routo/core';
import { Provider, useRouterState } from '@routo/react';

const HOME = 'router/HOME';
const POST = 'router/POST';

const routes = [
  {
    id: HOME,
    path: '/',
  },
  {
    id: POST,
    path: '/posts/:id',
  },
];

const router = createRouter(routes);

const mapping = {
  [HOME]: () => 'Home',
  [POST]: () => 'Post',
  [NOT_FOUND]: () => 'Not Found',
};

const Router = () => {
  const state = useRouterState();
  const Component = mapping[state.id];

  return <Component />;
};

const Root = () => (
  <Provider router={router}>
    <Router />
  </Provider>
);

License

MIT © Timofey Dergachev

0.8.0

2 years ago

0.7.0

3 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.0

4 years ago