Skip to content

Commit 968cad9

Browse files
committed
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit into fix-size-limit-config
2 parents f830cc8 + 3927c0c commit 968cad9

File tree

7 files changed

+31
-13
lines changed

7 files changed

+31
-13
lines changed

docs/api/createSlice.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ reducers: (create) => {
353353

354354
### `extraReducers`
355355

356-
Conceptually, each slice reducer "owns" its slice of state. There's also a natural correspondance between the update logic defined inside `reducers`, and the action types that are generated based on those.
356+
Conceptually, each slice reducer "owns" its slice of state. There's also a natural correspondence between the update logic defined inside `reducers`, and the action types that are generated based on those.
357357

358358
However, there are many times that a Redux slice may also need to update its own state in response to action types that were defined elsewhere in the application (such as clearing many different kinds of data when a "user logged out" action is dispatched). This can include action types defined by another `createSlice` call, actions generated by a `createAsyncThunk`, RTK Query endpoint matchers, or any other action. In addition, one of the key concepts of Redux is that many slice reducers can independently respond to the same action type.
359359

docs/rtk-query/api/created-api/hooks.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ selectFromResult: () => ({})
370370
- `trigger`: A function that triggers an update to the data based on the provided argument. The trigger function returns a promise with the properties shown above that may be used to handle the behavior of the promise
371371
- `mutationState`: A query status object containing the current loading state and metadata about the request, or the values returned by the `selectFromResult` option where applicable.
372372
Additionally, this object will contain
373-
- a `reset` method to reset the hook back to it's original state and remove the current result from the cache
373+
- a `reset` method to reset the hook back to its original state and remove the current result from the cache
374374
- an `originalArgs` property that contains the argument passed to the last call of the `trigger` function.
375375
376376
#### Description

docs/rtk-query/api/fetchBaseQuery.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ export const api = createApi({
336336
query: () => ({
337337
url: `users`,
338338
// Example: we know the users endpoint is _really fast_ because it's always cached.
339-
// We can assume if its over > 1000ms, something is wrong and we should abort the request.
339+
// We can assume if it's over > 1000ms, something is wrong and we should abort the request.
340340
timeout: 1000,
341341
}),
342342
}),

docs/rtk-query/usage/mutations.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Below are some of the most frequently used properties on the "mutation result" o
118118
- `isLoading` - When true, indicates that the mutation has been fired and is awaiting a response.
119119
- `isSuccess` - When true, indicates that the last mutation fired has data from a successful request.
120120
- `isError` - When true, indicates that the last mutation fired resulted in an error state.
121-
- `reset` - A method to reset the hook back to it's original state and remove the current result from the cache
121+
- `reset` - A method to reset the hook back to its original state and remove the current result from the cache
122122

123123
:::note
124124

packages/toolkit/src/query/core/buildThunks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".`
519519
arg.forceRefetch ?? (arg.subscribe && baseFetchOnMountOrArgChange)
520520

521521
if (refetchVal) {
522-
// Return if its true or compare the dates because it must be a number
522+
// Return if it's true or compare the dates because it must be a number
523523
return (
524524
refetchVal === true ||
525525
(Number(new Date()) - Number(fulfilledVal)) / 1000 >= refetchVal

packages/toolkit/src/query/endpointDefinitions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ interface EndpointDefinitionWithQueryFn<
135135
* if (randomVal < 0.9) {
136136
* return { data: 'tails' }
137137
* }
138-
* return { error: { status: 500, statusText: 'Internal Server Error', data: "Coin landed on it's edge!" } }
138+
* return { error: { status: 500, statusText: 'Internal Server Error', data: "Coin landed on its edge!" } }
139139
* }
140140
* // highlight-end
141141
* })

packages/toolkit/src/query/react/buildHooks.ts

+25-7
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,27 @@ import { useStableQueryArgs } from './useSerializedStableValue'
5353
import { useShallowStableValue } from './useShallowStableValue'
5454

5555
// Copy-pasted from React-Redux
56+
const canUseDOM = () =>
57+
!!(
58+
typeof window !== 'undefined' &&
59+
typeof window.document !== 'undefined' &&
60+
typeof window.document.createElement !== 'undefined'
61+
)
62+
63+
const isDOM = /* @__PURE__ */ canUseDOM()
64+
65+
// Under React Native, we know that we always want to use useLayoutEffect
66+
67+
const isRunningInReactNative = () =>
68+
typeof navigator !== 'undefined' && navigator.product === 'ReactNative'
69+
70+
const isReactNative = /* @__PURE__ */ isRunningInReactNative()
71+
72+
const getUseIsomorphicLayoutEffect = () =>
73+
isDOM || isReactNative ? useLayoutEffect : useEffect
74+
5675
export const useIsomorphicLayoutEffect =
57-
typeof window !== 'undefined' &&
58-
!!window.document &&
59-
!!window.document.createElement
60-
? useLayoutEffect
61-
: useEffect
76+
/* @__PURE__ */ getUseIsomorphicLayoutEffect()
6277

6378
export interface QueryHooks<
6479
Definition extends QueryDefinition<any, any, any, any, any>,
@@ -522,7 +537,7 @@ export type UseMutationStateResult<
522537
> = TSHelpersNoInfer<R> & {
523538
originalArgs?: QueryArgFrom<D>
524539
/**
525-
* Resets the hook state to it's initial `uninitialized` state.
540+
* Resets the hook state to its initial `uninitialized` state.
526541
* This will also remove the last result from the cache.
527542
*/
528543
reset: () => void
@@ -690,7 +705,10 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
690705
// isFetching = true any time a request is in flight
691706
const isFetching = currentState.isLoading
692707
// isLoading = true only when loading while no data is present yet (initial load with no data in the cache)
693-
const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized) && !hasData && isFetching
708+
const isLoading =
709+
(!lastResult || lastResult.isLoading || lastResult.isUninitialized) &&
710+
!hasData &&
711+
isFetching
694712
// isSuccess = true when data is present
695713
const isSuccess = currentState.isSuccess || (isFetching && hasData)
696714

0 commit comments

Comments
 (0)