Skip to content
This repository was archived by the owner on Nov 23, 2024. It is now read-only.

Commit 5fd5fff

Browse files
markeriksonmsutkowskiphryneas
authored
Docs content and layout editing pass (#65)
* Rework splash page descriptions and layout * Rename "Quick Start" to "Getting Started" * More splash screen layout updates * Update theme to match other Redux docs sites - Updated lots of formatting - Removed excess inline code formatting - Adding some code highlights - Removed some words like "simply" - Added description to the "Comparison" page - Updated "Comparison" table formatting Co-authored-by: Matt Sutkowski <[email protected]> Co-authored-by: Lenz Weber <[email protected]>
1 parent 8ae62b8 commit 5fd5fff

26 files changed

+432
-451
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This is an experiment to create a generic api client based on (and potentially t
1515

1616
For now, look at [The CodeSandbox CI](https://ci.codesandbox.io/status/rtk-incubator/rtk-query/pr/1) for the latest experimental package builds and up-to-date example sandboxes.
1717

18-
Then follow along with the [Quick Start](https://rtk-query-docs.netlify.app/introduction/quick-start) - make sure to use the latest CodeSandbox build when installing :)
18+
Then follow along with the [Getting Started instructions](https://rtk-query-docs.netlify.app/introduction/getting-started) - make sure to use the latest CodeSandbox build when installing :)
1919

2020
```sh title="Example installation"
2121
yarn add https://pkg.csb.dev/rtk-incubator/rtk-query/commit/0271589e/@rtk-incubator/rtk-query

docs/api/createApi.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ export const {
6161

6262
#### middleware
6363

64-
This is a standard redux middleware and is responsible for things like [polling](../concepts/polling), [garbage collection](#keepunuseddatafor) and a handful of other things. Make sure it's [included in your store](../introduction/quick-start#add-the-service-to-your-store).
64+
This is a standard redux middleware and is responsible for things like [polling](../concepts/polling), [garbage collection](#keepunuseddatafor) and a handful of other things. Make sure it's [included in your store](../introduction/getting-started#add-the-service-to-your-store).
6565

6666
#### reducer
6767

68-
A standard redux reducer that enables core functionality. Make sure it's [included in your store](../introduction/quick-start#add-the-service-to-your-store).
68+
A standard redux reducer that enables core functionality. Make sure it's [included in your store](../introduction/getting-started#add-the-service-to-your-store).
6969

7070
### `endpoints` returned by `createApi`
7171

@@ -248,7 +248,7 @@ function defaultTransformResponse(baseQueryReturnValue: unknown) {
248248
}
249249
```
250250
251-
To change it, simply provide a function that looks like:
251+
To change it, provide a function that looks like:
252252
253253
```ts
254254
transformResponse: (response) => response.some.deeply.nested.property;

docs/api/fetchBaseQuery.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ It takes all standard options from fetch's [`RequestInit`](https://developer.moz
2222
(headers: Headers, api: { getState: () => unknown }) => Headers;
2323
```
2424

25-
2625
```ts title="Return types of fetchBaseQuery"
2726
Promise<{
2827
data: any;
@@ -38,7 +37,7 @@ Promise<{
3837

3938
### Using `fetchBaseQuery`
4039

41-
To use it, simply import it when you are [creating an API service definition](../introduction/quick-start#create-an-api-service).
40+
To use it, import it when you are [creating an API service definition](../introduction/getting-started#create-an-api-service).
4241

4342
```ts title="src/services/pokemon.ts"
4443
import { createApi, fetchBaseQuery } from '@rtk-incubator/rtk-query';
@@ -85,10 +84,10 @@ const baseQuery = fetchBaseQuery({
8584

8685
There is more behavior that you can define on a per-request basis that extends the default options available to the `RequestInit` interface.
8786

88-
- [`params`](#setting-the-query-string)
89-
- [`body`](#setting-the-body)
90-
- [`responseHandler`](#parsing-a-Response)
91-
- [`validateStatus`](#handling-non-standard-response-status-codes)
87+
- [`params`](#setting-the-query-string)
88+
- [`body`](#setting-the-body)
89+
- [`responseHandler`](#parsing-a-Response)
90+
- [`validateStatus`](#handling-non-standard-response-status-codes)
9291

9392
```ts title="endpoint request options"
9493
interface FetchArgs extends RequestInit {

docs/concepts/conditional-fetching.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar_label: Conditional Fetching
55
hide_title: true
66
---
77

8-
# `Conditional Fetching`
8+
# Conditional Fetching
99

1010
If you want to prevent a query from automatically running, you can use the `skip` parameter in a hook.
1111

docs/concepts/error-handling.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ sidebar_label: Error Handling
55
hide_title: true
66
---
77

8-
# `Error Handling`
8+
# Error Handling
9+
10+
## Coming Soon

docs/concepts/mutations.md

+23-20
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ sidebar_label: Mutations
55
hide_title: true
66
---
77

8-
# `Mutations`
8+
# Mutations
99

1010
Unlike `useQuery`, `useMutation` returns a tuple. The first item in the tuple is the `trigger` function and the second element contains an object with `status`, `error`, and `data`. Additionally, `useMutation` also makes `internalQueryArgs`, `originalArgs`,
1111
and `endpoint` available for inspection.
1212

13-
Also unlike the `useQuery` hook, the `useMutation` hook doesn't execute automatically. To run a mutation you have to call the `trigger` function.
13+
Unlike the `useQuery` hook, the `useMutation` hook doesn't execute automatically. To run a mutation you have to call the trigger function returned as the first tuple value from the hook.
1414

1515
```js title="Example of all mutation endpoint options"
1616
const api = createApi({
@@ -29,7 +29,7 @@ const api = createApi({
2929
```
3030

3131
:::info
32-
Notice the `onStart`, `onSuccess`, `onError` methods? Make sure to check out how they can be used for [optimistic updates](./optimistic-updates)
32+
Notice the `onStart`, `onSuccess`, `onError` methods? Be sure to check out how they can be used for [optimistic updates](./optimistic-updates)
3333
:::
3434

3535
### Type interfaces
@@ -62,7 +62,7 @@ export interface MutationApi<ReducerPath extends string, Context extends {}> {
6262
}
6363
```
6464

65-
### Basic mutation
65+
### Basic Mutation
6666

6767
This is a modified version of the complete example you can see at the bottom of the page to highlight the `updatePost` mutation. In this scenario, a post is fetched with `useQuery`, and then a `EditablePostName` component is rendered that allows us to edit the name of the post.
6868

@@ -73,6 +73,7 @@ export const PostDetail = () => {
7373
const { data: post } = postApi.hooks.getPost.useQuery(id);
7474

7575
const [
76+
// highlight-next-line
7677
updatePost, // This is the mutation trigger
7778
{ isLoading: isUpdating }, // You can use the `isLoading` flag, or do custom logic with `status`
7879
] = postApi.hooks.updatePost.useMutation();
@@ -82,13 +83,17 @@ export const PostDetail = () => {
8283
<EditablePostName
8384
name={post.name}
8485
onUpdate={(name) => {
85-
// Execute the trigger with the `id` and updated `name`
86-
return updatePost({ id, name })
87-
.then((result) => {
88-
// Do something with the result
89-
console.log('Update Result', result);
90-
})
91-
.catch((error) => console.error('Update Error', error));
86+
return (
87+
// highlight-start
88+
// Execute the trigger with the `id` and updated `name`
89+
updatePost({ id, name })
90+
// highlight-end
91+
.then((result) => {
92+
// Do something with the result
93+
console.log('Update Result', result);
94+
})
95+
.catch((error) => console.error('Update Error', error))
96+
);
9297
}}
9398
isLoading={isUpdating}
9499
/>
@@ -99,21 +104,19 @@ export const PostDetail = () => {
99104

100105
### Advanced mutations with revalidation
101106

102-
In the real world, it's very common that a developer would want to resync their local data cache with the server after performing a mutation (aka `revalidation`). RTK Query takes a more centralized approach to this and requires you to configure the invalidation behavior in your API service definition. Before getting started, let's cover some new terms:
107+
In the real world, it's very common that a developer would want to resync their local data cache with the server after performing a mutation (aka "revalidation"). RTK Query takes a more centralized approach to this and requires you to configure the invalidation behavior in your API service definition. Before getting started, let's cover some new terms used when defining an endpoint in a service:
103108

104-
1. **Entities**
109+
#### Entities
105110

106-
- In short, entities are just a name that you can give to a specific collection of data to control caching and invalidation behavior. For example, in an application that has both `Posts` and `Users`, you would define `entityTypes: ['Posts', 'Users']` when calling `createApi`.
111+
For RTK Query, _entities_ are just a name that you can give to a specific collection of data to control caching and invalidation behavior, and are defined in an `entityTypes` argument. For example, in an application that has both `Posts` and `Users`, you would define `entityTypes: ['Posts', 'Users']` when calling `createApi`.
107112

108-
2. **Provides**
113+
#### Provides
109114

110-
- A `query` can _provide_ entities to the cache.
111-
- Accepts either an array of `{type: string, id?: string|number}` or a callback that returns such an array. That function will be passed the result as the first argument and the argument originally passed into the `query` method as the second argument.
115+
A _query_ can _provide_ entities to the cache. The `provides` argument can both be an array of `string` (such as `['Posts']`), `{type: string, id?: string|number}` or a callback that returns such an array. That function will be passed the result as the first argument and the argument originally passed into the `query` method as the second argument.
112116

113-
3. **Invalidates**
117+
#### Invalidates
114118

115-
- A `mutation` can _invalidate_ specific entities in the cache.
116-
- Can both be an array of `string` (such as `['Posts']`), `{type: string, id?: string|number}` or a callback that returns such an array. That function will be passed the result as the first argument and the argument originally passed into the `query` method as the second argument.
119+
A _mutation_ can _invalidate_ specific entities in the cache. The `invalidates` argument can both be an array of `string` (such as `['Posts']`), `{type: string, id?: string|number}` or a callback that returns such an array. That function will be passed the result as the first argument and the argument originally passed into the `query` method as the second argument.
117120

118121
### Scenarios and Behaviors
119122

docs/concepts/optimistic-updates.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ sidebar_label: Optimistic Updates
55
hide_title: true
66
---
77

8-
# `Optimistic Updates`
8+
# Optimistic Updates
99

1010
When you're performing an update on some data that _already exists_ in the cache via [`useMutation`](./mutations), RTK Query gives you a few tools to implement an optimistic update. This can be a useful pattern for when you want to give the user the impression that their changes are immediate.
1111

12-
The core concepts are pretty straightforward - in the `onStart` phase of a mutation, you manually set the cached data via `updateQueryResult`, and then `onError` you roll it back via `patchQueryResult`. You don't have to worry about the `onSuccess` lifecycle here.
12+
The core concepts are:
13+
14+
- in the `onStart` phase of a mutation, you manually set the cached data via `updateQueryResult`
15+
- then, in `onError`, you roll it back via `patchQueryResult`. You don't have to worry about the `onSuccess` lifecycle here.
1316

1417
```ts title="Example optimistic update mutation"
1518
const api = createApi({

docs/concepts/pagination.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ sidebar_label: Pagination
55
hide_title: true
66
---
77

8-
# `Pagination`
8+
# Pagination
99

10-
RTK Query makes it simple to integrate with a standard index-based pagination API. This is the most common form of pagination that you'll need to implement. This is how simple it can be:
10+
RTK Query makes it straightforward to integrate with a standard index-based pagination API. This is the most common form of pagination that you'll need to implement.
1111

12-
#### Setup an endpoint to accept a page `arg`
12+
## Setup an endpoint to accept a page `arg`
1313

1414
```ts title="src/app/services/posts.ts"
1515
import { createApi, fetchBaseQuery } from "@rtk-incubator/rtk-query";
@@ -35,7 +35,7 @@ export const api = createApi({
3535
export const { useListPostsQuery } = api.hooks;
3636
```
3737

38-
#### Trigger the next page by incrementing the `page` state variable
38+
## Trigger the next page by incrementing the `page` state variable
3939

4040
```ts title="src/features/posts/PostsManager.tsx"
4141
const PostList = () => {
@@ -68,7 +68,7 @@ const PostList = () => {
6868
};
6969
```
7070
71-
### Example
71+
## Example
7272
7373
In the following example, you'll see `Loading` on the initial query, but then as you move forward we'll use the next/previous buttons as a _fetching_ indicator while any non-cached query is performed. When you go back, the cached data will be served instantaneously.
7474

docs/concepts/polling.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar_label: Polling
55
hide_title: true
66
---
77

8-
# `Polling`
8+
# Polling
99

1010
Polling gives you the ability to have a 'real-time' effect by causing a query to run at a specified interval. To enable polling for a query, pass a `pollingInterval` to the `useQuery` hook or action creator with an interval in milliseconds:
1111

docs/concepts/prefetching.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar_label: Prefetching
55
hide_title: true
66
---
77

8-
# `Prefetching`
8+
# Prefetching
99

1010
The goal of prefetching is to make data fetch _before_ the user navigates to a page or attempts to load some known content.
1111

docs/concepts/queries.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ sidebar_label: Queries
55
hide_title: true
66
---
77

8-
# `Queries`
8+
# Queries
99

10-
This is the most basic feature of `RTK Query`. A `query` can be performed with any data fetching library of your choice, but the general recommendation is that you only use queries for requests that retrieve data. For anything that alters data on the server or will possibly invalidate the cache, you should use a [Mutation](./mutations).
10+
This is the most basic feature of RTK Query. A query operation can be performed with any data fetching library of your choice, but the general recommendation is that you only use queries for requests that retrieve data. For anything that alters data on the server or will possibly invalidate the cache, you should use a [Mutation](./mutations).
1111

12-
By default, `RTK Query` ships with [fetchBaseQuery](../api/fetchBaseQuery), which is just a lightweight [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) wrapper that automatically handles request headers and response parsing in a manner similar to common libraries like `axios`.
12+
By default, RTK Query ships with [`fetchBaseQuery`](../api/fetchBaseQuery), which is a lightweight [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) wrapper that automatically handles request headers and response parsing in a manner similar to common libraries like `axios`.
1313

1414
> Depending on your environment, you may need to polyfill `fetch` with `whatwg-fetch` if you choose to use `fetchBaseQuery` or `fetch` on it's own.
1515
1616
### Performing queries with React Hooks
1717

1818
If you're using React Hooks, RTK Query does a few additional things for you. The primary benefit is that you get a render-optimized hook that allows you to have 'background fetching'.
1919

20+
Hooks are automatically generated based on the name of the `endpoint` in the service definition. An endpoint field with `getPost: builder.query()` will generate a hook named `useGetPostQuery`.
21+
2022
Here is an example of a `PostDetail` component:
2123

2224
```ts title="Example"

0 commit comments

Comments
 (0)