mobx-react-router icon indicating copy to clipboard operation
mobx-react-router copied to clipboard

will v3 with latest mobx?

Open alisman opened this issue 5 years ago • 3 comments

Does anyone know if v3 of this package can be made to work with latest mobx? When I upgrade mobx, I get store.location undefined

alisman avatar Nov 05 '20 17:11 alisman

I upgrade this tool with mobx v6 and make a pull request. Before the pr is merged, you can use @superwf/mobx-react-router temporarily.

superwf avatar Nov 09 '20 03:11 superwf

Happens to me too, will love to make it work with mobx v6

chensara avatar Nov 12 '20 08:11 chensara

If you're stuck on react-router v5, and want to incorporate mobx v6, you can do the following:

import { RouterStore, syncHistoryWithStore } from 'mobx-react-router';
import { createBrowserHistory } from 'history';
import { makeObservable } from 'mobx';

export const routerStore = new RouterStore();
export const browserHistory = syncHistoryWithStore(createBrowserHistory(), routerStore);

makeObservable(routerStore);

The only important call here is makeObservable(routerStore). This picks up the existing observable decorator and wires everything up.

joshleblanc avatar Feb 10 '22 12:02 joshleblanc