Refreshing Components #70
-
I will illustrate with an example: There are 3 buttons which load conditionally in a blade file, each is an alpine component. If one of the views which was originally not added when the page loaded (but added later by Livewire), gets called, we would receive an "Uncaught (in promise) Error: Component not found". I originally solved this by just loading all elements and conditionally hiding them instead of removing them. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
If I understand correctly: That error triggers occurs when the component you are trying to connect to doesn't exist. It's just a simple selector though (Line 31). document.querySelector(`[x-data][x-id="${componentName}"], [x-data]#${componentName}`) To avoid it, you should add probably only use |
Beta Was this translation helpful? Give feedback.
If I understand correctly:
That error triggers occurs when the component you are trying to connect to doesn't exist.
It's just a simple selector though (Line 31).
To avoid it, you should add probably only use
$component()
when you know the element will be there, or otherwise add in your own check first to make sure it's there. I think you could do a try/catch and just ignore the error. It's not an expensive operation.