Renderhook Cannot Received Dispatched Event

Hello, I am using a renderhook to include some custom JS on a specific page using:
FilamentView::registerRenderHook(
PanelsRenderHook::BODY_START,
fn (): string => Blade::render('@livewire(\'star-j-s\')'),
scopes: [
ListOrders::class,
]
);
FilamentView::registerRenderHook(
PanelsRenderHook::BODY_START,
fn (): string => Blade::render('@livewire(\'star-j-s\')'),
scopes: [
ListOrders::class,
]
);
The JS renders on the page correctly. I have confirmed that it renders properly using:
<div>
</div>

<script>
console.log('rendered');
</script>
<div>
</div>

<script>
console.log('rendered');
</script>
I cannot handle any dispatched events. I have tried:
document.addEventListener('livewire:init', () => {
Livewire.on('paymentSuccessful', event => {
})
// and ...
$wire.on('paymentSuccessful') // this throws an error saying $wire is undefined
// and...
window.addEventListener('paymentSuccessful', event => {

})
document.addEventListener('livewire:init', () => {
Livewire.on('paymentSuccessful', event => {
})
// and ...
$wire.on('paymentSuccessful') // this throws an error saying $wire is undefined
// and...
window.addEventListener('paymentSuccessful', event => {

})
Do I need to modify the StarJS Livewire component? What am I doing wrong? Thanks!
2 Replies
LeandroFerreira
LeandroFerreira3mo ago
GitHub
Cannot listen for Livewire events if component placed inside Filame...
Package Widgets Package Version v3.2.44 How can we help you? I am trying to place a Livewire component inside a Filament Widget that has inline scripts. I have this inside my Livewire Component bla...
bwurtz999
bwurtz9993mo ago
Really appreciate the link! Unfortunately, when I add @push('scripts') I cannot log anything to the console. When I remove @push, I can log the initial render and the livewire init. But still cannot listen for events I switched the renderhook to PAGE_END and now I can log to the console on load from within @push('scripts') But still no luck with listening for events Update: I've tried converting this to a custom page and still no luck. I can console.log when the scripts first render but I cannot capture any events I figured it out. I need to dispatch from within the ->action() of the headerAction. I was trying to dispatch from a different function. I think after would work as well if I remember correctly. Hope this helps someone else in the future