MST with Inertia JS #2228
Replies: 1 comment 1 reply
-
Interesting. I've never used Inertia before. Seems cool! My first thought is that you might want to take those Inertia listeners and set them up somehow in MST's volatile state: https://mobx-state-tree.js.org/concepts/volatiles That's particularly useful for storing values you can't serialize, and I personally use it for things like timeouts and intervals for coordination. You could then have the listeners either call actions to mutate state, or you could make your state computed views based on the current values of what's in volatile. That's just an initial intuition. If I have time this weekend I will try to set up a test project and see if I have a stronger/better recommendation. If you have the opportunity to share a demo repo at all, I'd be able to give even better advice after messing around with it. Either way, I hope this helps to start, and I'll take a deeper look later! |
Beta Was this translation helpful? Give feedback.
-
Hi there,
After looking at many of the other state mgmt solutions, I really like mobx/mst, so the work is much appreciated.
My question is:
I'm using react with Inertia JS (and a Laravel backend) but in practice, there's quite a bit of prop-drilling that comes into play. So I'd like to have MST pickup on the changes from any/all inertia requests that go out.
So far, I've setup some models like so:
(For additional context, I'm sharing some dummy models I'm testing with (Book, Genre))
PageModel.ts
BookModel.ts
GenreModel.ts
DashboardPage.ts
The
DashboardPage
is essentially a view model that I've setup which is intended to:Mind you, I'm very new to MST, so you may have a better suggestion on all this.
Ultimately, I've gotten the initial render working, but if/when I some state updates (e.g. using , the store isn't picking up on that.
What would be your recommended way in wiring up the MST store in a way that automatically picks up on the prop changes that Inertia is providing. For reference, Inertia does provide a way to listen to each visit made here. There's also a
div
with an id ofapp
with adata-page="{...}"
where{...}
is the stringified JSON of the data returned from the server.Note: I'm referring to Inertia V2, but the question would be the same if asking for V1
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions