S
SolidJS15mo ago
Metru

Question about onError

onError((err) => {
console.error(err);
})

onMount(() => {
loadUserData(params.username)
.then(setUser)
})
onError((err) => {
console.error(err);
})

onMount(() => {
loadUserData(params.username)
.then(setUser)
})
I've got a throw inside my loadUserData because I thought onError would catch it, so I guess I've misused onError.
5 Replies
Metru
Metru15mo ago
Also, am I able to safely make onMount's callback async?
lxsmnsyc
lxsmnsyc15mo ago
the only function that can handle errors on all of JS is "window.onerror" and that's on the browser you can imagine onError as try-catch. If you run a setTimeout in try, and the callback throws, would you expect the catch block to receive it?
Metru
Metru15mo ago
So I take it onError is less of a "catch-all" within this component, and more of a if literally this component function throws. From the docs "Registers an error handler method that executes when child scope errors", I had assumed the solid compiler did something to be able to react to errors originating from the component. Wasn't sure how much "magic" solid is doing vs something like svelte.
lxsmnsyc
lxsmnsyc15mo ago
the compiler only touches JSX. What you see is what Solid looks like with or without the compiler
Metru
Metru15mo ago
Gotcha So without jsx, solid would run in the browser directly? Thats pretty neat