From 2fe98c97129eb97dd6b2159cb2d79245f9ed52b0 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Thu, 23 Jan 2025 19:16:52 +0200 Subject: [PATCH] docs: add a note about installing tanstack query as a dev dependency (#11123) --- .../app/learn/customization/customize-admin/route/page.mdx | 6 ++++++ .../app/learn/customization/customize-admin/widget/page.mdx | 6 ++++++ www/apps/book/app/learn/fundamentals/admin/tips/page.mdx | 6 ++++++ .../app/admin-components/components/table/page.mdx | 6 ++++++ www/apps/resources/app/integrations/guides/sanity/page.mdx | 6 ++++++ www/apps/resources/app/js-sdk/page.mdx | 6 ++++++ 6 files changed, 36 insertions(+) diff --git a/www/apps/book/app/learn/customization/customize-admin/route/page.mdx b/www/apps/book/app/learn/customization/customize-admin/route/page.mdx index 5a093589c4..d9149b5692 100644 --- a/www/apps/book/app/learn/customization/customize-admin/route/page.mdx +++ b/www/apps/book/app/learn/customization/customize-admin/route/page.mdx @@ -410,6 +410,12 @@ You first define pagination-related variables: Then, you use `useQuery` from [Tanstack (React) Query](https://tanstack.com/query/latest) to query the Medusa server. Tanstack Query provides features like asynchronous state management and optimized caching. + + +Do not install Tanstack Query as that will cause unexpected errors in your development. If you prefer installing it for better auto-completion in your code editor, make sure to install `v5.64.2` as a development dependency. + + + In the `queryFn` function that executes the query, you use the JS SDK's `client.fetch` method to send a request to your custom API route. The first parameter is the route's path, and the second is an object of request configuration and data. You pass the query parameters in the `query` property. This sends a request to the [Get Brands API route](#1-get-brands-api-route), passing the pagination query parameters. Whenever `currentPage` is updated, the `offset` is also updated, which will send a new request to retrieve the brands for the current page. diff --git a/www/apps/book/app/learn/customization/customize-admin/widget/page.mdx b/www/apps/book/app/learn/customization/customize-admin/widget/page.mdx index 13ac3187e9..547c5f473d 100644 --- a/www/apps/book/app/learn/customization/customize-admin/widget/page.mdx +++ b/www/apps/book/app/learn/customization/customize-admin/widget/page.mdx @@ -147,6 +147,12 @@ Since the widget is injected at the top of the product details page, the widget In the widget, you use [Tanstack (React) Query](https://tanstack.com/query/latest) to query the Medusa server. Tanstack Query provides features like asynchronous state management and optimized caching. In the `queryFn` function that executes the query, you use the JS SDK to send a request to the [Get Product API Route](!api!/admin#products_getproductsid), passing `+brand.*` in the `fields` query parameter to retrieve the product's brand. + + +Do not install Tanstack Query as that will cause unexpected errors in your development. If you prefer installing it for better auto-completion in your code editor, make sure to install `v5.64.2` as a development dependency. + + + You then render a section that shows the brand's name. In admin customizations, use components from the [Medusa UI package](!ui!) to maintain a consistent user interface and design in the dashboard. --- diff --git a/www/apps/book/app/learn/fundamentals/admin/tips/page.mdx b/www/apps/book/app/learn/fundamentals/admin/tips/page.mdx index 83d158fd72..7def722750 100644 --- a/www/apps/book/app/learn/fundamentals/admin/tips/page.mdx +++ b/www/apps/book/app/learn/fundamentals/admin/tips/page.mdx @@ -12,6 +12,12 @@ In this chapter, you'll find some tips for your admin development. To send a request to an API route in the Medusa Application, use Medusa's [JS SDK](!resources!/js-sdk) with [Tanstack Query](https://tanstack.com/query/latest). Both of these tools are installed in your project by default. + + +Do not install Tanstack Query as that will cause unexpected errors in your development. If you prefer installing it for better auto-completion in your code editor, make sure to install `v5.64.2` as a development dependency. + + + First, create the file `src/admin/lib/config.ts` to setup the SDK for use in your customizations: ```ts diff --git a/www/apps/resources/app/admin-components/components/table/page.mdx b/www/apps/resources/app/admin-components/components/table/page.mdx index 411fe15512..95a4ab3d45 100644 --- a/www/apps/resources/app/admin-components/components/table/page.mdx +++ b/www/apps/resources/app/admin-components/components/table/page.mdx @@ -311,6 +311,12 @@ You can change the query to send a request to a custom API route as explained in + + +Do not install Tanstack Query as that will cause unexpected errors in your development. If you prefer installing it for better auto-completion in your code editor, make sure to install `v5.64.2` as a development dependency. + + + `useQuery` returns an object containing `data`, which holds the response fields including the products and pagination fields. Then, to display the table, replace the `TODO` with the following: diff --git a/www/apps/resources/app/integrations/guides/sanity/page.mdx b/www/apps/resources/app/integrations/guides/sanity/page.mdx index 155c866a02..352ce131d6 100644 --- a/www/apps/resources/app/integrations/guides/sanity/page.mdx +++ b/www/apps/resources/app/integrations/guides/sanity/page.mdx @@ -1442,6 +1442,12 @@ In this section, you'll add a widget in the product details page. The widget wil To send requests from admin customizations to the Medusa server, you need to use Medusa's [JS SDK](../../../js-sdk/page.mdx). You'll also use [Tanstack Query](https://tanstack.com/query/latest) to benefit from features like data caching and invalidation. + + +Do not install Tanstack Query as that will cause unexpected errors in your development. If you prefer installing it for better auto-completion in your code editor, make sure to install `v5.64.2` as a development dependency. + + + To configure the JS SDK, create the file `src/admin/lib/sdk.ts` with the following content: ```ts title="src/admin/lib/sdk.ts" diff --git a/www/apps/resources/app/js-sdk/page.mdx b/www/apps/resources/app/js-sdk/page.mdx index a84f9942d1..b9970b4c4c 100644 --- a/www/apps/resources/app/js-sdk/page.mdx +++ b/www/apps/resources/app/js-sdk/page.mdx @@ -352,6 +352,12 @@ In admin customizations, use [Tanstack Query](https://tanstack.com/query/latest) Tanstack Query is installed by default in your Medusa application. + + +Do not install Tanstack Query as that will cause unexpected errors in your development. If you prefer installing it for better auto-completion in your code editor, make sure to install `v5.64.2` as a development dependency. + + + Use the [configured SDK](#setup-js-sdk) with the [useQuery](https://tanstack.com/query/latest/docs/framework/react/reference/useQuery#usequery) Tanstack Query hook to send `GET` requests, and [useMutation](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation#usemutation) hook to send `POST` or `DELETE` requests. For example: