swr

React Hooks for Data Fetching

MIT License

Downloads
9.7M
Stars
29.3K
Committers
182

Bot releases are hidden (Show)

swr - 1.2.0-beta.1

Published by shuding almost 3 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/vercel/swr/compare/1.1.2...1.2.0-beta.1

swr - 1.2.0-beta.0

Published by shuding almost 3 years ago

Highlights of This Release

Dedicated API for Optimistic Updates with Auto Rollback on Error

There are now some new options in mutate:

mutate(patchUser(user), {
  optimisticData: user,
  populateCache: true,
  rollbackOnError: true,
  revalidate: true,
})

Here the cache will be immediately updated to user, the “optimistic value”. And then a request (remote mutation) is started via patchUser(user) and the response will be written to the cache. If that request fails, the original result will be rolled back safely so the optimistic value will be gone. And after all those finish, a revalidation will start to fetch the latest value.

This is extremely helpful for building the optimistic UI pattern.

You can do the same for the global mutate, just remember to pass the key. Also, the current mutate APIs stay unchanged so mutate(data, false) works the same.

Here's an example: https://codesandbox.io/s/swr-basic-forked-k5hps.

What's Changed

Full Changelog: https://github.com/vercel/swr/compare/1.1.2...1.2.0-beta.0

swr - 1.1.2

Published by shuding almost 3 years ago

Highlights of This Release

Use the Latest Fetcher Function

SWR will now use the latest fetcher function passed to the hook, when sending the request. Previously it uses the initial snapshotted fetcher.

Avoid Unnecessary Auto Revalidations

When refocusing on the window with state changes (like clicking a button that changes the SWR key immediately), SWR now avoids revalidations if they're not necessary. Details can be found in #1720.

New Types for useSWRInfinite

Two types for useSWRInfinite are added: SWRInfinteHook and SWRInfinteKeyLoader. You can use them to type the hook and the getKey function.

New populateCache option for mutate

A new option to control if the mutation data should be written to the cache. You can find the details in #1729.

What's Changed

New Contributors

Full Changelog: https://github.com/vercel/swr/compare/1.1.1...1.1.2

swr - 1.1.2-beta.1

Published by shuding almost 3 years ago

Highlights of This Release

1. More Tests and Better Code Coverage

We now have 23 test suits of 202 total test cases, with a 98.06% test coverage. The core files and main functionalities are now 100% covered. Kudos to @promer94 for improving it!

2. Use the Latest Fetcher Function

SWR will now use the latest fetcher function passed to the hook, when sending the request. Previously it uses the initial snapshotted fetcher.

3. Avoid Unnecessary Auto Revalidations

When refocusing on the window with state changes (like clicking a button that changes the SWR key immediately), SWR now avoids revalidations if they're not necessary. Details can be found in #1720.

4. New Types for useSWRInfinite

Two types for useSWRInfinite are added: SWRInfinteHook and SWRInfinteKeyLoader. You can use them to type the hook and the getKey function.

What's Changed

New Contributors

Full Changelog: https://github.com/vercel/swr/compare/1.1.2-beta.0...1.1.2-beta.1

swr - 1.1.2-beta.0

Published by shuding almost 3 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/vercel/swr/compare/1.1.1...1.1.2-beta.0

swr - 1.1.1

Published by shuding almost 3 years ago

Highlights of This Release

Dynamic refreshInterval

You can now pass a function as refreshInterval, to dynamically return the interval (in millisecond) til the next request, based on the current data:

useSWR('key', fetcher, {
  refreshInterval: function (data: Data | undefined) {
    if (!data) return 3000 // Initial request 
    return data.next_update
  }
})

If return 0, polling will be stopped.

What's Changed

New Contributors

Full Changelog: https://github.com/vercel/swr/compare/1.1.0...1.1.1

swr - 1.1.0

Published by shuding almost 3 years ago

Highlights for This Release

1. Built-in & stable serialization for SWR keys

useSWR({ query: graphql`...`, variables }, fetcher)
useSWR({ query: graphql`...`, variables }, fetcher)
useSWR({ variables, query: graphql`...` }, fetcher)
// ^all recognized as the same resource

For array keys too, it's safe to do the following:

useSWR([ `...`, { variables } ], fetcher)

2. revalidateFirstPage for useSWRInfinite

This is a new added option for useSWRInfinite (defaults to true), you can use it to control if the first page should be revalidated when changing the size or doing a mutation.

3. Better TypeScript support

  • Key / arguments
  • Conditional / dependent
  • Constant keys
  • Returned data

image

What's Changed

New Contributors

Full Changelog: https://github.com/vercel/swr/compare/1.0.1...1.1.0

swr -

Published by shuding almost 3 years ago

Patches

  • Chore: rename major branch to main: #1664
  • Fix keyloader index and previousPageData type: #1669
  • Fix: Add defaults for SWRResponse: #1609

Credits

Huge thanks to @huozhi, @promer94, and @TakahiroHimi for helping!

swr -

Published by shuding almost 3 years ago

Patches

  • Fix: supports ssr in ie11(#1657): #1659
  • Type: disbale inference when data generic is provided: #1658

Credits

Huge thanks to @Sh031224 and @promer94 for helping!

swr -

Published by shuding almost 3 years ago

Minor Changes

  • Build: output without minification: #1650
  • Tweak types: #1640

Patches

  • Fix: typos: #1647

Credits

Huge thanks to @promer94, @huozhi, and @nguyenyou for helping!

swr -

Published by shuding almost 3 years ago

Minor Changes

  • Revert "chore: Add type: "module" and use .mjs extension" (#1618): #1604

Patches

  • Enhance: bind removeEventListener: #1596

Credits

Huge thanks to @huozhi for helping!

swr -

Published by shuding almost 3 years ago

Patches

  • Chore: Add type: "module" and use .mjs extension: #1604
swr -

Published by shuding almost 3 years ago

Minor Changes

  • Fix: Support for functions that return false: #1586
  • Fix: adds undefined as valid Key type to allow falsy Key or Key(): #1594
  • Revert "mark data and error as readonly " (#1570): #1514

Patches

  • Fix react-native issue: #1583
  • Fix: compatible with miniprogram: #1595
  • Change config alteration process in withMiddleware to be immutable: #1556
  • Fix mutate argument for infinite: #1602

Credits

Huge thanks to @TakahiroHimi, @morgs32, @aFINKndreas, @zhaomengfan, and @junsushin-dev for helping!

swr -

Published by shuding almost 3 years ago

Patches

  • Small fixes: #1541
  • Chore: Refactor cleanupState: #1544
  • Feat: using latest version of axios with fetch interceptor: #1548
  • Test: Add test case for mutation deduplication: #1549
  • Test: speed up with @swc-node/jest: #1569
  • Optimizations: #1578

Credits

Huge thanks to @danestves and @huozhi for helping!

swr -

Published by shuding about 3 years ago

Minor Changes

  • Mark data and error as readonly: #1514
  • Add revalidateFirstPage option to infinite: #1538

Patches

  • Output code coverage: #1511
  • Test: Add tests for reconnect and merge-config: #1530
  • Fix: Only trigger the success event if not discarded: #1529
  • Chore: Code refactoring: #1533
  • Fix: Reusing cache provider: #1539
  • Chore: fix ts comments: #1540
  • Fix: Ensure mutate accepts undefined as the data: #1515

Credits

Huge thanks to @timas130 and @huozhi for helping!

swr -

Published by shuding about 3 years ago

Minor Changes

  • Feat: Add new onDiscarded option: #1523

Patches

  • Chore: Code refactoring: #1521
  • Fix error events not deduped: #1522
swr -

Published by shuding about 3 years ago

Patches

  • Fix: Invalidate the key when mutating without revalidating: #1498
  • Example: add ref checking condition: #1504
  • Fix: Refactor core revalidate function and fix isValidating state bug: #1493
  • Chore: Remove duplicate configs: #1507
  • Typing: fix-type-generation: #1509
  • Chroe: use yalc for local development: #1508

Credits

Huge thanks to @huozhi and @promer94 for helping!

swr -

Published by shuding about 3 years ago

Minor Changes

  • Type useSWR fetcher: #1477

Patches

  • Ci: multiple dir type checking: #1492
  • Chore: Improve project file structure: #1497
  • Chore: Refine type interfaces: #1496
  • Chore: Upgrade eslint and add local cache: #1499

Credits

Huge thanks to @promer94 and @huozhi for helping!

swr -

Published by shuding about 3 years ago

Minor Changes

  • Add react 18 to peerDependencies: #1467
  • Upgrade typescript to 4.4.3: #1486

Patches

  • Test: refactor immutable and infinite hook tests: #1466
  • Test: refactor integration and loading tests: #1473
  • Test: refactor key, middlewares, and suspense tests: #1474
  • Test: refactor offline and refresh tests: #1483
  • Build(deps): bump tmpl from 1.0.4 to 1.0.5: #1484
  • Chore: Code refactoring: #1482

Credits

Huge thanks to @huozhi and @koba04 for helping!

swr -

Published by shuding about 3 years ago

Minor Changes

  • Should treat key change as remount: #1430
  • Stable hash: #1429
  • Enhance: provider release handlers: #1449

Patches

  • Test: add tests for a global cache: #1421
  • Chore: always use config ref: #1397
  • Typing: use separated constants instead of enum: #1425
  • Test: add render utilities and remove TestSWRConfig: #1435
  • Fix initial isValidating when isPaused() returns true: #1440
  • Build: no emit on error: #1446
  • Chore: remove unused typings: #1448
  • Test: refactor use-swr-cache-test: #1442
  • Refactor code related to unsubscribing global listeners: #1451
  • Chore: refactor infinite: #1452
  • Test: refactor concurrent rendering tests: #1457
  • Test: refactor config tests: #1458
  • Revert "feat: add a warning for invalid arguments with suspense mode " (#1460): #1402
  • Test: refactor mutation tests: #1459
  • Fix: Support IE11: #1463

Credits

Huge thanks to @huozhi, @koba04, @anirudh1713, @anothertempore, and @amannn for helping!