Replies: 1 comment
-
Personally, I'd recommend an API route that lets you modify several resources at once. But regarding your example, since each mutation is an individual request, I'd simply use a React state. Eg. const [isLoading, setIsLoading] = useState(false);
const [pullDeviceConfig, pullDeviceConfigResult] = usePullDeviceConfigMutation()
const handlePullConfig = async () => {
setIsLoading(true);
const promises = selectedIds.map(async id => {
const result = await pullDeviceConfig({
'device_id': id
})
if (result.data) {
...
}
if (result.error) {
...
}
})
try {
await Promise.all(promises)
} catch (err) { // do somthing }
setLoading(false);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there.
While using the RTK Query, I faced the following problem: I have a user interface with a list of devices, and I want to be able to select multiple devices in the list, run some action on them, and show the loading spinner for each device for which the action is performed. To do this, I have to make several parallel requests to some endpoint on the backend, and I do it like this:
Since each request has a different duration, in order to correctly display the status of loading spinners, I need to get the value of something like pullDeviceConfigResult.isLoading for each individual spinner. As example, in React Query you can use
useQueries
, that gives you an Array of results, and do something like this:But is there a way to do the same for mutations in RTK Query?
Beta Was this translation helpful? Give feedback.
All reactions