From dad3b6d950e85959478174d93209f2602805ed5e Mon Sep 17 00:00:00 2001 From: Mikael Lirbank Date: Wed, 7 Dec 2022 15:30:47 -0800 Subject: [PATCH 1/2] Fetcher function TS example --- pages/docs/getting-started.en-US.mdx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pages/docs/getting-started.en-US.mdx b/pages/docs/getting-started.en-US.mdx index 199077ef..d94781be 100644 --- a/pages/docs/getting-started.en-US.mdx +++ b/pages/docs/getting-started.en-US.mdx @@ -25,6 +25,12 @@ For normal RESTful APIs with JSON data, first you need to create a `fetcher` fun const fetcher = (...args) => fetch(...args).then(res => res.json()) ``` +Or with TypeScript: + +```jsx +const fetcher = (...args: Parameters) => fetch(...args).then((res) => res.json()); +``` + If you want to use GraphQL API or libs like Axios, you can create your own fetcher function. Check here for more examples. From 8e3e4cfc9a56edd6b81a9b5ad23be1476196e171 Mon Sep 17 00:00:00 2001 From: Mikael Lirbank Date: Wed, 7 Dec 2022 15:42:41 -0800 Subject: [PATCH 2/2] Fetcher function TS example (all languages) --- pages/docs/getting-started.es-ES.mdx | 6 ++++++ pages/docs/getting-started.ja.mdx | 6 ++++++ pages/docs/getting-started.ko.mdx | 6 ++++++ pages/docs/getting-started.pt-BR.mdx | 6 ++++++ pages/docs/getting-started.ru.mdx | 6 ++++++ pages/docs/getting-started.zh-CN.mdx | 6 ++++++ 6 files changed, 36 insertions(+) diff --git a/pages/docs/getting-started.es-ES.mdx b/pages/docs/getting-started.es-ES.mdx index 4cbf60cb..ea0919e8 100644 --- a/pages/docs/getting-started.es-ES.mdx +++ b/pages/docs/getting-started.es-ES.mdx @@ -26,6 +26,12 @@ del `fetch` nativo: const fetcher = (...args) => fetch(...args).then(res => res.json()) ``` +Or with TypeScript: + +```jsx +const fetcher = (...args: Parameters) => fetch(...args).then((res) => res.json()); +``` + Si tu quieres usar API GraphQL o librerías como Axios, puedes crear tu propia función fetcher. Consulta aqui para ver más ejemplos. diff --git a/pages/docs/getting-started.ja.mdx b/pages/docs/getting-started.ja.mdx index 3da3a6bd..f9f864c0 100644 --- a/pages/docs/getting-started.ja.mdx +++ b/pages/docs/getting-started.ja.mdx @@ -25,6 +25,12 @@ JSON データを使用する通常の RESTful API の場合、まずネイテ const fetcher = (...args) => fetch(...args).then(res => res.json()) ``` +Or with TypeScript: + +```jsx +const fetcher = (...args: Parameters) => fetch(...args).then((res) => res.json()); +``` + もし GraphQL API または Axios のようなライブラリを使いたい場合は、独自のフェッチャー関数を作ることができます。 その他の例はこちらをご覧ください。 diff --git a/pages/docs/getting-started.ko.mdx b/pages/docs/getting-started.ko.mdx index ec896fb0..9784ffaa 100644 --- a/pages/docs/getting-started.ko.mdx +++ b/pages/docs/getting-started.ko.mdx @@ -25,6 +25,12 @@ JSON 데이터를 사용하는 일반적인 RESTful API라면 먼저 네이티 const fetcher = (...args) => fetch(...args).then(res => res.json()) ``` +Or with TypeScript: + +```jsx +const fetcher = (...args: Parameters) => fetch(...args).then((res) => res.json()); +``` + GraphQL API 또는 Axios와 같은 라이브러리를 사용하려면 여러분만의 fetcher 함수를 생성하면 됩니다. 여기에서 더 많은 예시를 확인하세요. diff --git a/pages/docs/getting-started.pt-BR.mdx b/pages/docs/getting-started.pt-BR.mdx index 0a445aa8..f6630cf3 100644 --- a/pages/docs/getting-started.pt-BR.mdx +++ b/pages/docs/getting-started.pt-BR.mdx @@ -25,6 +25,12 @@ Para APIs RESTful normais com dados JSON, primeiro você precisa criar uma funç const fetcher = (...args) => fetch(...args).then(res => res.json()) ``` +Or with TypeScript: + +```jsx +const fetcher = (...args: Parameters) => fetch(...args).then((res) => res.json()); +``` + Se você quer usar APIs GraphQL ou outras bibliotecas como Axios, você pode criar sua própria função fetcher. Veja aqui para mais exemplos. diff --git a/pages/docs/getting-started.ru.mdx b/pages/docs/getting-started.ru.mdx index 192a9acf..4bfaa94b 100644 --- a/pages/docs/getting-started.ru.mdx +++ b/pages/docs/getting-started.ru.mdx @@ -26,6 +26,12 @@ npm install swr const fetcher = (...args) => fetch(...args).then(res => res.json()) ``` +Or with TypeScript: + +```jsx +const fetcher = (...args: Parameters) => fetch(...args).then((res) => res.json()); +``` + Если вы хотите использовать GraphQL API или библиотеки, такие как Axios, вы можете создать свою собственную fetcher-функцию. diff --git a/pages/docs/getting-started.zh-CN.mdx b/pages/docs/getting-started.zh-CN.mdx index 467f7599..52213154 100644 --- a/pages/docs/getting-started.zh-CN.mdx +++ b/pages/docs/getting-started.zh-CN.mdx @@ -25,6 +25,12 @@ npm install swr const fetcher = (...args) => fetch(...args).then((res) => res.json()) ``` +Or with TypeScript: + +```jsx +const fetcher = (...args: Parameters) => fetch(...args).then((res) => res.json()); +``` + 如果要使用 GraphQL API 或类似 Axios 的库,可以自己创建 fetcher 函数。 点击 这里 查看更多示例。