MobX React Router Utils
Routing utils to use with RouterStore (from mobx-react-router) on your MobX stores.
Install it
yarn add mobx-react-router-utils
Use it
import { computedRouteParam, setRoutingStore } from 'mobx-react-router-utils'
setRoutingStore(routingStore)
const routes = {
search: '/search',
citySearch: '/cities/:city'
}
class DemoSearchStore {
city = computedRouteParam('city', {
patterns: [routes.citySearch],
})
checkIn = computedRouteParam('checkIn', {
patterns: [routes.search, routes.citySearch],
parse: _parseDate,
format: _formatDate,
defaultValue: 'temecula'
})
checkOut = computedRouteParam('checkOut', {
patterns: [routes.search, routes.citySearch],
parse: _parseDate,
format: _formatDate,
})
setCity = (city: Maybe<string>) => {
this.city.push(city, {
pattern: !city && routes.search,
cleanParams: true,
cleanParams: [
this.checkIn,
this.checkOut
]
})
}
setPeriod = (checkIn: Maybe<Date>, checkOut: Maybe<Date>) => {
this.checkIn.push(checkIn)
this.checkOut.replace(checkOut)
}
}