Skip to content

onPress handler on Button component has a return type of void only #4392

@mounis-bhat

Description

@mounis-bhat

📝 Feedback

The onPress handler on Button component has a return type of void however many tasks done using buttons can be asynchronous and the expect the type of promise returning function.

🔦 Context

Faced this issue when calling an API with a function and es-lint was throwing the following error:

Promise-returning function provided to attribute where a void return was expected.eslint@typescript-eslint/no-misused-promises

💻 Code Sample

async function loginWithGoogle() {
    setIsLoading(true)
    try {
      await signIn()
    } catch (e) {
      toast.error("Something went wrong")
    } finally {
      setIsLoading(false)
    }
  }
<Button
  className="mx-auto w-full max-w-sm"
  onPress={loginWithGoogle}
  isDisabled={isLoading}
>
  {isLoading ? (
    <Loader2 className="mr-2 h-5 w-5 animate-spin " />
  ) : (
    <GoogleSvg />
  )}
  <span>Google</span>
</Button>

🌍 Your Environment

| react-aria-components |
| Edge Chromium |
| Windows 11 |

🧢 Your Company/Team

Independent Developer

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions