Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types for SWRConfig mismatch the documentation #561

Closed
samuelhulla opened this issue Jan 25, 2024 · 1 comment
Closed

Types for SWRConfig mismatch the documentation #561

samuelhulla opened this issue Jan 25, 2024 · 1 comment

Comments

@samuelhulla
Copy link

samuelhulla commented Jan 25, 2024

The properties in the react-native section seem no longer compatible with the SWRConfiguration type.

In the docs you have the example of

<SWRConfig
  value={{
    provider: () => new Map(),
    isOnline() {
      /* Customize the network state detector */
      return true
    },
    isVisible() {
      /* Customize the visibility state detector */
      return true
    },
    initFocus(callback) {
      /* Register the listener with your state provider */
    },
    initReconnect(callback) {
      /* Register the listener with your state provider */
    }
  }}
>

This however misaligns with the exported type of SWRConfiguration as the following properties are missing

  • provider
  • initFocus
  • initReconnect

Upon further inspection of the exported index.d.ts, the missing properties come from type Config which is however not exported.

type Config = SWRConfiguration & Partial<ProviderConfiguration> & {
    provider?: (cache: Readonly<Cache>) => Cache;
};

where ProviderConfiguration is defined as

type ProviderConfiguration = {
    initFocus: (callback: () => void) => (() => void) | void;
    initReconnect: (callback: () => void) => (() => void) | void;
};

Unless there's an internal reason for not exposing these methods (which seems contradictory with the react-native documentation) the exported type for SWRConfig should be Config instead

Furthermore when importing the component SWRConfig it just defaults to :any, seems a resolution issue with directly importing react over just importing it's types in the SWRConfig definition. import ReactExports from 'react'

@samuelhulla
Copy link
Author

Sorry, didn't realize when clicking on posting issue referral actually posts on the specific docs repo. Closing this issue, adding issue to SWR core repo + PR fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant