mobx-wouter
Version:
<img src="assets/logo.png" align="right" height="156" alt="logo" />
95 lines (61 loc) • 2.82 kB
Markdown
<img src="assets/logo.png" align="right" height="156" alt="logo" />
[![NPM version][npm-image]][npm-url] [![test status][github-test-actions-image]][github-actions-url] [![build status][github-build-actions-image]][github-actions-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
[]: http://img.shields.io/npm/v/mobx-wouter.svg
[]: http://npmjs.org/package/mobx-wouter
[]: https://github.com/js2me/mobx-wouter/workflows/Build/badge.svg
[]: https://github.com/js2me/mobx-wouter/workflows/Test/badge.svg
[]: https://github.com/js2me/mobx-wouter/actions
[]: https://img.shields.io/npm/dm/mobx-wouter.svg
[]: https://npmjs.org/package/mobx-wouter
[]: https://bundlephobia.com/result?p=mobx-wouter
[]: https://badgen.net/bundlephobia/minzip/mobx-wouter
_**MobX** integration with **Wouter**_
Router for client navigation
```ts
const history = createBrowserHistory();
// const history = createMemoryHistory();
// const history = createHashHistory();
const router = createRouter({
history,
// baseUrl
// abortSignal
// useStartViewTransition
queryParams: createQueryParams({
history,
}),
});
```
Exports from [mobx-location-history](https://js2me.github.io/mobx-location-history)
Simple [`ViewModel`](https://js2me.github.io/mobx-view-model/api/view-models/interface.html) wrapper for pages
```ts
import { PageViewModelBase } from 'mobx-wouter';
class HomePageVM extends PageViewModelBase<{ pathParam: string }> {
@observable
accessor value = 'value';
mount() {
super.mount();
document.title = 'Home';
// do something
}
}
```
HOC for integration `PageViewModel` with view component of **React**
```tsx
import { ViewModelProps } from 'mobx-view-model';
import { withPageViewModel } from 'mobx-wouter';
const HomePageView = observer(({ model }: ViewModelProps<HomePageVM>) => {
return <div>{`render value - ${model.value}`}</div>
})
export const HomePage = withPageViewModel(HomePageVM)(HomePageView);
```
Same as [`withPageViewModel()`](src/page-view-model/with-page-view-model.tsx) but with lazy loading view and view model