Skip to content

Feature request: exported types / easier augmentation patterns #4164

@james-dawson-wegmans

Description

@james-dawson-wegmans

Feature request

Description

useSWR's types are extremely complex and difficult to replicate. I've been working on a variety of wrappers for useSWR in our project and because swr doesn't export most of its types, it has been nearly impossible to ensure that my wrappers offer the exact same API surface as useSWR.

Expected Behavior

I'd expect to be able to import types like Arguments, Key, State, etc.

Additional Context

Rationale for wanting this:

I created an in-project hook named useAuthenticatedSWR, which is meant to do everything useSWR does, but also taps into my project's authentication system to automatically pass null into the swrKey if auth isn't ready yet. Because of the complex types for useSWR, I had to limit the options that my custom wrapper can accept even though I'm just passing everything through.


I assume that perhaps function overloads are part of this complexity. I'm not sure if swr can provide an easier gateway to being extended in the future, but that's the hope. Wrapping something to configure it would ideally be a lot less difficult than it is.

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