I have several livewire components that process data from an API. Rather than have each component call the API, how can I handle it such that they share the same API call.
I thought of passing the API call response in from the controller to the view, but then the page would need to wait for the api response, right?
@clarg18, generally it's not fun to pass around a lot of data between livewire components.
you can emit it using events or save it in the session. For your waiting question, you can use wire:init to let the page load while waiting for a query to finish. There is also, prefetching which is useful sometimes.
@clarg18, no you'd want to call it from the livewire component. like the example. You have to do the work somewhere. I actually think its one of the cool uses of livewire. The page can load, your api gets triggered. Show a loading message, etc. until the response arrives.
@webrobert Ok ... I'm interesting too ... if I have well understood, wire:init can be used if you want to load immediately some part of the page, and defer (via wire:init) the loading of other part of the page.
@vincent15000, as example I just finished a stock chart feature, the page loads, then wire:init orders the chart, after it's ready, I use a browser event to send the data to chart js. This is one component.
@clarg18 You could do that. I don't know what you are doing? Like is said when possible I use fewer components. But if I need say, a guests location (I get it from an api), I save it in session/etc. And emit an event after it's set.