Skip to content

Commit e81cb47

Browse files
authored
docs(QueryStatus): change from enum to union type (TanStack#2073)
* docs: add query status typing change from enum to string literal * docs: underline links in headings as their color is inherited from the heading and links are indistinguishable from the heading itself * docs: move query status typing change to typescript section * docs: underline level four heading links too * docs: remove unnecessary old line from diff
1 parent 7b14ef5 commit e81cb47

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

docs/src/components/markdown.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@
156156
@apply text-xl;
157157
}
158158

159+
.markdown > h2 > a,
160+
.markdown > h3 > a,
161+
.markdown > h4 > a {
162+
@apply underline;
163+
}
164+
159165
.markdown > .markdown ul {
160166
@apply list-disc;
161167
}

docs/src/pages/guides/migrating-to-react-query-3.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,37 @@ setConsole({
416416

417417
In version 3 **this is done automatically when React Query is used in React Native**.
418418

419+
420+
### Typescript
421+
#### `QueryStatus` has been changed from an [enum](https://www.typescriptlang.org/docs/handbook/enums.html#string-enums) to a [union type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types)
422+
423+
So, if you were checking the status property of a query or mutation against a QueryStatus enum property you will have to check it now against the string literal the enum previously held for each property.
424+
425+
Therefore you have to change the enum properties to their equivalent string literal, like this:
426+
- `QueryStatus.Idle` -> `'idle'`
427+
- `QueryStatus.Loading` -> `'loading'`
428+
- `QueryStatus.Error` -> `'error'`
429+
- `QueryStatus.Success` -> `'success'`
430+
431+
Here is an example of the changes you would have to make:
432+
433+
```diff
434+
- import { useQuery, QueryStatus } from 'react-query';
435+
+ import { useQuery } from 'react-query';
436+
437+
const { data, status } = useQuery(['post', id], () => fetchPost(id))
438+
439+
- if (status === QueryStatus.Loading) {
440+
+ if (status === 'loading') {
441+
...
442+
}
443+
444+
- if (status === QueryStatus.Error) {
445+
+ if (status === 'error') {
446+
...
447+
}
448+
```
449+
419450
## New features
420451

421452
#### Query Data Selectors

0 commit comments

Comments
 (0)