sponge
sponge
SSolidJS
Created by sponge on 4/2/2024 in #support
Delegated custom events
Should delegated events work with custom events sent via HTMLElement dispatchEvent? The (new) docs mention:
For any other events, such as custom events or events you wish not to be delegated, the on: attribute will add an event listener as-is.
If you need to attach an event listener to an element that is not supported by Solid's event delegation, such as a custom event in a custom element, you can use the on:__ form.
I'm wanting to use delegated events so I can have a component that uses onMyEvent, and also allow users of that component to add their own onMyEvent on the same component. Even though the docs imply I need to use the on: form to attach a native event, the delegated events seem to work correctly. TS does complain about the JSX, though (I have setup the event in JSX.CustomEvents/CustomCaptureEvents): Property 'onMyEvent' does not exist on type 'HTMLAttributes<HTMLDivElement>'. Did you mean '"on:myevent"'? Should I be able to use delegated events for this custom event, and if I can, how do I get TS to stop complaining about that property not existing?
7 replies
SSolidJS
Created by sponge on 1/26/2024 in #support
useNavigate wrapped in <Router>
Hello! I'm trying to use useNavigate inside a top-level element so I can setup some event listeners that will trigger navigations app-wide: https://playground.solidjs.com/anonymous/2ea655b2-d438-4ead-ac5d-a6f134d79e26 gives me Uncaught Error: Make sure your app is wrapped in a <Router /> Several Stack Overflow answers said that you can't use useNavigate inside an event listener, which is what I was originally doing, so I tried to move it into a new component that is nested underneath <Router> but it seems like useNavigate only works on a component inside <Route>. Is this intentional behavior, despite the error message looking for <Router>? Is there any other way to instantiate useNavigate at a high enough level that it will always trigger regardless of the current route? Thank you!
5 replies