{"id":21595114,"url":"https://github.com/kazakago/swr-compose","last_synced_at":"2026-02-26T10:47:43.464Z","repository":{"id":63739967,"uuid":"566693483","full_name":"kazakago/swr-compose","owner":"kazakago","description":"\"React SWR\" ported for Jetpack Compose \u0026 Compose Multiplatform","archived":false,"fork":false,"pushed_at":"2025-08-13T15:24:15.000Z","size":1178,"stargazers_count":61,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-13T15:26:28.410Z","etag":null,"topics":["android","compose-multiplatform","jetpack-compose","kotlin","swr"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kazakago.png","metadata":{"files":{"readme":"README-ja.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-11-16T08:09:06.000Z","updated_at":"2025-08-13T13:20:25.000Z","dependencies_parsed_at":"2023-10-05T00:29:37.697Z","dependency_job_id":"2bdc98ec-548c-4a70-9567-ec61d94d2595","html_url":"https://github.com/kazakago/swr-compose","commit_stats":{"total_commits":243,"total_committers":2,"mean_commits":121.5,"dds":"0.49382716049382713","last_synced_commit":"53ef41c3fcabc4d4a8a650406860a01b24a1d361"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/kazakago/swr-compose","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazakago%2Fswr-compose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazakago%2Fswr-compose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazakago%2Fswr-compose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazakago%2Fswr-compose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kazakago","download_url":"https://codeload.github.com/kazakago/swr-compose/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazakago%2Fswr-compose/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271470214,"owners_count":24765347,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","compose-multiplatform","jetpack-compose","kotlin","swr"],"created_at":"2024-11-24T17:26:34.761Z","updated_at":"2026-02-26T10:47:43.414Z","avatar_url":"https://github.com/kazakago.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SWR for Compose\n\n[![Maven Central](https://img.shields.io/maven-central/v/com.kazakago.swr.compose/swr.svg)](https://central.sonatype.com/namespace/com.kazakago.swr.compose)\n[![javadoc](https://javadoc.io/badge2/com.kazakago.swr.compose/swr/javadoc.svg)](https://javadoc.io/doc/com.kazakago.swr.compose/swr)\n[![Test](https://github.com/KazaKago/swr-compose/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/KazaKago/swr-compose/actions/workflows/test.yml?query=branch%3Amain)\n[![License](https://img.shields.io/github/license/kazakago/swr-compose.svg)](LICENSE)\n\n[React SWR](https://swr.vercel.app)を[Jetpack Compose](https://developer.android.com/jetpack/compose)と[Compose Multiplatform](https://www.jetbrains.com/lp/compose-multiplatform/) 向けに移植したクローンライブラリです。  \nサポートされているプラットフォームはAndroid、Desktop(JVM)、iOS、Webです。  \n\nオリジナルの`React SWR`のAPI仕様をできる限り踏襲しており、オプションの大部分をサポートしています。  \n\n## \"SWR\"とは？\n\nReact SWRによると、\"SWR\"とは下記を指します。  \n\n\u003e “SWR” という名前は、 [HTTP RFC 5861](https://www.rfc-editor.org/rfc/rfc5861) で提唱された HTTP キャッシュ無効化戦略である stale-while-revalidate に由来しています。 SWR は、まずキャッシュからデータを返し（stale）、次にフェッチリクエストを送り（revalidate）、最後に最新のデータを持ってくるという戦略です。\n\n## インストール\n\n下記の `*.*.*` を最新のバージョンに置き換えてbuild.gradleのdependenciesに追加してください。 [![Maven Central](https://img.shields.io/maven-central/v/com.kazakago.swr.compose/swr.svg)](https://central.sonatype.com/namespace/com.kazakago.swr.compose)  \n\n```kotlin\nimplementation(\"com.kazakago.swr.compose:swr:*.*.*\")\n```\n\n## クイックスタート\n\nオリジナルの`React SWR`と同様に、fetcher関数を用意したら`useSWR()`にキーとともにセットするだけです。  \n戻り値に対してKotlinの[分解宣言](https://kotlinlang.org/docs/destructuring-declarations.html) を用いると`React SWR`と同じように記述できます。  \n\n```kotlin\nprivate val fetcher: suspend (key: String) -\u003e String = {\n    getNameApi.execute(key)\n}\n\n@Composable\nfun Profile() {\n    val (data, error) = useSWR(\"/api/user\", fetcher)\n\n    if (error != null) {\n        Text(\"failed to load\")\n    } else if (data == null) {\n        Text(\"loading...\")\n    } else {\n        Text(\"hello $data!\")\n    }\n}\n```\n\n## 例\n\nKotlin/Wasmによるライブデモは[**こちら**](https://kazakago.github.io/swr-compose/).\n\n詳細な実装例は[**exampleモジュール**](composeApp)を参照して下さい。Compose Multiplatformアプリとして実行できます。\n\n## サポートされている機能\n\n| Feature名                                                                      | サポート                    | 補足                        |\n|-------------------------------------------------------------------------------|-------------------------|---------------------------|\n| [Options](https://swr.vercel.app/docs/options)                                | [下記参照](#サポートされているオプション) |                           |\n| [Global Configuration](https://swr.vercel.app/docs/global-configuration)      | ✅                       |                           |\n| [Data Fetching](https://swr.vercel.app/docs/data-fetching)                    | ✅                       |                           |\n| [Error Handling](https://swr.vercel.app/docs/error-handling)                  | ✅                       |                           |\n| [Auto Revalidation](https://swr.vercel.app/docs/revalidation)                 | ✅                       |                           |\n| [Conditional Data Fetching](https://swr.vercel.app/docs/conditional-fetching) | ✅                       |                           |\n| [Arguments](https://swr.vercel.app/docs/arguments)                            | ✅                       |                           |\n| [Mutation](https://swr.vercel.app/docs/mutation)                              | ✅️                      |                           |\n| [Pagination](https://swr.vercel.app/docs/pagination)                          | ✅                       |                           |\n| [Prefetching Data](https://swr.vercel.app/docs/prefetching)                   | ✅️                      | `useSWRPreload()`から利用できます |\n| [Suspense](https://swr.vercel.app/docs/suspense)                              | ❌                       |                           |\n| [Middleware](https://swr.vercel.app/docs/middleware)                          | ❌                       |                           |\n\n## サポートされているオプション\n\nReact SWRに対して、以下のオプションをサポートしています。  \nhttps://swr.vercel.app/docs/options\n\n| オプション名                                                    | サポート | デフォルト値                                                              |\n|-----------------------------------------------------------|------|---------------------------------------------------------------------|\n| suspense                                                  | ❌    |                                                                     |\n| fetcher(args)                                             | ✅    |                                                                     |\n| revalidateIfStale                                         | ✅    | true                                                                |\n| revalidateOnMount                                         | ✅    | `fallbackData`が設定されていないときのみtrue                                     |\n| revalidateOnFocus                                         | ✅    | true                                                                |\n| revalidateOnReconnect                                     | ✅    | true                                                                |\n| refreshInterval                                           | ✅    | 0.seconds (無効)                                                      |\n| refreshWhenHidden                                         | ✅    | false                                                               |\n| refreshWhenOffline                                        | ✅    | false                                                               |\n| shouldRetryOnError                                        | ✅    | true                                                                |\n| dedupingInterval                                          | ✅    | 2.seconds                                                           |\n| focusThrottleInterval                                     | ✅    | 5.seconds                                                           |\n| loadingTimeout                                            | ✅    | 3.seconds                                                           |\n| errorRetryInterval                                        | ✅    | 5.seconds                                                           |\n| errorRetryCount                                           | ✅    |                                                                     |\n| fallback                                                  | ✅    |                                                                     |\n| fallbackData                                              | ✅    |                                                                     |\n| keepPreviousData                                          | ✅    | false                                                               |\n| onLoadingSlow(key, config)                                | ✅    |                                                                     |\n| onSuccess(data, key, config)                              | ✅    |                                                                     |\n| onError(err, key, config)                                 | ✅    |                                                                     |\n| onErrorRetry(err, key, config, revalidate, revalidateOps) | ✅    | [指数バックオフ](https://en.wikipedia.org/wiki/Exponential_backoff) アルゴリズム |\n| compare(a, b)                                             | ❌    |                                                                     |\n| isPaused()                                                | ✅    | false                                                               |\n| use                                                       | ❌    |                                                                     |\n\n## パフォーマンスについて\n\n[Deduplication](https://swr.vercel.app/docs/advanced/performance#deduplication) や[Deep Comparison](https://swr.vercel.app/docs/advanced/performance#deep-comparison) はサポートされていますが、Kotlinの言語仕様上[Dependency Collection](https://swr.vercel.app/docs/advanced/performance#dependency-collection) には対応しないため、本家React SWRに比べると単純な再レンダリング（re-compose）の回数は多くなることがあります。  \n\nしかしながら、子のComposable関数へ渡す引数を（例えばdataのみにするなど）絞ることでパフォーマンスの低下を防ぐことが可能です。  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazakago%2Fswr-compose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkazakago%2Fswr-compose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazakago%2Fswr-compose/lists"}