S
SolidJS5mo ago
aryzing

Can on__ handler be async?

Seems that having async handlers works fine,
const button = <button onClick={doSomethingAsync}>Click me</button>
const button = <button onClick={doSomethingAsync}>Click me</button>
although the particular ESLint config I'm working with doesn't like it,
Promise-returning function provided to attribute where a void return was expected. (eslint@typescript-eslint/no-misused-promises)
Promise-returning function provided to attribute where a void return was expected. (eslint@typescript-eslint/no-misused-promises)
Are async handlers supported? If so, do Solid's types need to be updated?
7 Replies
aryzing
aryzing5mo ago
Possibly updated the following?
interface EventHandler<T, E extends Event> {
(
e: E & {
currentTarget: T;
target: DOMElement;
}
- ): void;
+ ): Promise<void> | void
}
interface EventHandler<T, E extends Event> {
(
e: E & {
currentTarget: T;
target: DOMElement;
}
- ): void;
+ ): Promise<void> | void
}
thetarnav
thetarnav5mo ago
you can use promises and solid types do not need to be updated because void already means that it doesn’t care about what you return this seems like an issue with your eslint rule, not typescript
aryzing
aryzing5mo ago
Thanks for clarifying. Does void really mean that it doesn't care about the return value? Isn't it more like it doesn't expect a return value?
thetarnav
thetarnav5mo ago
yeah you can theoretically return anything and typescript won't complain (which is why an eslint rule might be useful to catch that, as it is weird do do that) but ts won't let you use the value returned by that function its a weird design but it means that any function will extend a (...a: any[]) => void type
aryzing
aryzing5mo ago
Got it, thanks!
Alex Lohr
Alex Lohr5mo ago
If the async thing you do is a request, it might be better to just use a signal's setter as event handler and use a derived version of the getter as source for a resource.
deluksic
deluksic5mo ago
We recently enabled no-misused-promises and a few more rules around promises to catch places where we did not .catch (pun intended). It is a very good thing that solidjs has void here, otherwise this rule would not work properly! Solidjs does NOT catch for you, you should do it yourself!
Want results from more Discord servers?
Add your server
More Posts
Can't route with Solid Router in subfolder of multi-page Vite appi have a folder structure where my solid app exists inside of `/prefabs` with children like `/prefacreateResource does not trigger suspense when its first-argument signal changesI have a modal component, with its open state managed by a signal. I want to fetch the data that showindow.location.search not empty after changing routeI need your help because I'm stuck and not sure how to proceed. I have a Solid.js app with the folloUndici fetch failed while building solid-start project on prod server@Halcyon while building solid-start project with `solid-start build` inside docker build with `nodNested Immer "produce" signals with componentsI'm trying to implement something like this, which would allow me to create "nested" signals that upHow can I pass data from middleware to frontend on solid-start.I have this middleware to validate a user accesstoken. And the response provides me the name of the Reading page states in Appis there a way to allow app reading states from a page component, similar to ``pageProps``?cannot use import statement outside a modulejust pushed my first solidstart app to azure cloud but vinxi start is failing. app works fine in locSolid-refresh with Webpack HMR errorsHello, I'm trying to integrate solid-refresh in a webpack based solid-js app to make development a bBest pattern when using createStore to store large amount of data for a large app?As the title says, what is the best pattern, is there an example on github or something you could sh