Is there any way to rerender a component from the outside?
for example when one component state changed then effect on another component by re-render it.
Hi @mvaliolahi - currently the simplest way to communicate between 2 components is through events.
You can dispatch an event from one component using the $dispatch magic function and then listen for that event on another component at the window level using x-on:event-name.window.
You'll want to dispatch the event with some data and then assign that data to the other component. This will cause Alpine.js to re-render the component.
@ryangjchandler Thanks
@ryangjchandler Hello again, can I dispatch event inside a click event like below:
The $dispatch magic variable isn't available in function callbacks. You can pass it through with @click="foo($dispatch)" and then accept as an argument in your function.
@ryangjchandler Thanks a lot.
Most helpful comment
The
$dispatchmagic variable isn't available in function callbacks. You can pass it through with@click="foo($dispatch)"and then accept as an argument in your function.