Skip to content

Conversation

huozhi
Copy link
Member

@huozhi huozhi commented Jun 11, 2022

Background

SWRConfig now merges the config passed in value property with SWR config from parent context, but this bring a problem that users have to be aware of how many layers of context are existing and there's no way to ignore the config from parent context

Feature

  • Support (parentConfig? Config) => Config overloading for SWRConfig value property

Then you can pick any properties from parent config and decide how to combine with the current SWR config, or you can just ignore any config property from parent context. e.g. you have a useSWR hook inside very deep level of the react tree, but you want it to keep the default config, you can just ignore all configs by ignoring all the parent configs.

Example

<SWRConfig value={config1}>
  <Page>
    <SWRConfig value={() => ({})}>
      <Main />
    </SWRConfig>
</SWRConfig>

@huozhi huozhi added this to the 2.0 milestone Jun 11, 2022
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 11, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1b254e4:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration
SWR-SSR Configuration

@huozhi huozhi marked this pull request as ready for review June 12, 2022 12:05
@huozhi huozhi requested a review from shuding as a code owner June 12, 2022 12:05
@huozhi huozhi force-pushed the feat/functional-config branch from 3171502 to 33b1907 Compare June 12, 2022 12:10
Copy link
Member

@shuding shuding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks

@shuding shuding merged commit 9263ca7 into main Jun 12, 2022
@shuding shuding deleted the feat/functional-config branch June 12, 2022 15:07
@koba04 koba04 mentioned this pull request Aug 5, 2022
13 tasks
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

Successfully merging this pull request may close these issues.

2 participants