mobx-wouter
Version:
<img src="assets/logo.png" align="right" height="156" alt="logo" />
86 lines (56 loc) • 2.79 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**_
Simple [`ViewModel`](https://github.com/js2me/mobx-view-model?tab=readme-ov-file#mobx-view-model) 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
Router for client navigation
Exports from [mobx-location-history](https://github.com/js2me/mobx-location-history)
```ts
import { MobxRouter, MobxLocation, MobxHistory, QueryParams } from "mobx-wouter";
const router = new MobxRouter({
history: //, new MobxLocation()
location: //, new MobxHistory()
queryParams: //, new QueryParams(),
abortSignal: //
})
```