Skip to content

[Feature request] Allow throwing an error in key getter function #361

@matthew-dean

Description

@matthew-dean

So, my actual use case is this:

I want to do client-side validation, and I have a general wrapper for useSWRV that passes back refs for data, error, etc. For some query parameters, I want to do client-side validation, and if it errors, I want to assign that to the error ref.

My first thought was: "Oh, maybe I can just throw an error in the key getter." However, that didn't work, as there's no error handling there. I thought maybe I could dynamically pass it to the fetcher function, but I don't see how without messing up hashing of the key. In other words: the query object is reactive, and will trigger a mutate automatically, so this validation has to happen "within" the useSWRV callback somehow.

IMO the easiest would be to allow errors to be thrown in the key getter, which then get assigned to error. Unless there's some other method you can think of?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions