-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using mobx-react-router with mobx-state-tree #665
Comments
What about if you moved the store creation to after the |
I just tried this briefly but it looks like is working! I'll keep this updated!
It happen when .push method is called in a mst action, I'm trying to translate your code in a mst friendly one, let's see if I can get somewhere |
@dbertella didn't fully get the status out of the conversation, can this issue be closed? |
Hi sorry I was distracted from many other things, the update is, it's working as it is as far as I know, so I guess we can close this issue. I was trying to rewrite mobx-react-router in a more mst way but for some reason I couldn't achieve the same functionality so I need to try again soon, might need to learn more about mobx and mobx-state-tree first. I'll keep you updated if I came up with a better solution. |
Confirmed, it's working. Just // router.js
import createHistory from 'history/createBrowserHistory';
import { RouterStore, syncHistoryWithStore } from 'mobx-react-router';
const routingStore = new RouterStore();
const browserHistory = createHistory();
export const history = syncHistoryWithStore(browserHistory, routingStore);
export default routingStore; // store.js
import Router from './router';
const Model = types.model({
router: types.optional(types.frozen),
});
export const store = Model.create({ router: Router }); |
@linonetwo if you change route with a |
@dbertella Both. To use |
I'm missing something because I can change route without a problem but |
@alisd23 I ended up writing my own implementation of mobx-react-router in mst, this is basically it. This version seems to work perfectly for me
|
Hmm the |
It doesn't update the store in my app even with the latest version. I create a simple sandbox with mobx-react-router: https://codesandbox.io/s/l4mn1o12jm that should log the snapshot in the console and it doesn't seem to work. @linonetwo can you check if I made any stupid mistake? This version instead https://codesandbox.io/s/913n1q60xw (with the mst transpiled version of mobx-react-router) works as expected |
I tried wiring up |
Basically the problem is that this line is updating only a property of a |
For anyone looking, I have now released an mst-react-router package, which hopefully should solve this problem. |
Hey, faced this problem just this morning and by using @alisd23 package everything works a breeze! Thank you very much. |
@alisd23 I started to get this typescript error that mst renamed property Snapshot. What was it renamed to? alisd23/mst-react-router#10 |
I opened an issue in that library already but I thought it can be more interesting to have it here.
Is it possible in your opinion to use mobx-react-router.
What I need is basically change route programmatically inside the mst actions using react-router.
What I'm doing (or trying to do) is:
My main store is something like this:
But then the
syncHistoryWithStore
is causing me an errorCannot assign to read only property 'history' of object '#<RouterStore>'
because I guess thetypes.frozen
don't accept mutability, am I correct?Is there a work around, a better way / better type for this?
The text was updated successfully, but these errors were encountered: