#Real-time searching
1 messages · Page 1 of 1 (latest)
Not sure if that would really work with Inertia. Since it's a global thing, you might be able to do this with a partial reload and using the middleware/global props
Ah really, yeah I thought this may be tricky as it’s somewhat out of scope. In a non Inertia app I’d just make an api call.
Thanks for the reply
That’s doable with the way Robert mentioned, but from my experience I’d highly advice just going with api.
If you’re performance conscious and you put global search inside shared props you’ll have to make all of your props on all of your pages lazy so that only the search is triggered on the partial reloads
Assuming youre not being performance conscious, the default way would be to share in the default inertia middleware, yes?
Yes inside the share method, but then let's say you're on a page which has 3 database calls outside of lazy props those 3 calls would still be executed when you call a partial reload for the global search (even though you won't see other properties in the callback)
I think this is sorta why I’d love to move away from Inertia eventually, so I can just do everything via an API. Then just apply rate limits instesd
Ah, ok I see. Definitely want to use API then. I never realized that "only" was just filtering which props were updated and not actually preventing the other code from running. It seems obvious now though, because how would it know not to... i guess like Charlie says this is a tradeoff of using default inertia features and not building your own API.
That's why I said that you would need to use lazy props
https://inertiajs.com/partial-reloads#lazy-data-evaluation
They're only evaluated when needed
That's why I'd recommend to always use closures for props. Without a closure doesn't have much value, and closures wouldn't be evaluated if the prop isn't requested
That optional method is a gem as well. Thanks to both of yuh.
That is in general a good practice but still there are a lot of times where separate props are dependent on each other + using route model bindings which (almost) always call a database query, so you still have to put some consideration on how you're handling partial reloads if you don't want to have redundant queries/operations