You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I upgraded react-query to version :
"react-query": "^3.5.11",
Based on the documentation, in react-query version 3 there is a mutateAsync return value introduced when useMutation(...).
In my react-native project, I use Axios for API call. I use the Axios provided interceptor to intercept each request. In the interceptor I would like to useMutation() to send a POST request like the following code shows:
const axios = Axios.create({
baseURL: 'https://api.myserver.com',
});
axios.interceptors.request.use(async (config) => {
// firstly I get data from local storage
const myData = myStorage.getMyData('my-data');
// I prepare the mutateAsync
const {mutateAsync} = useMutation((data) =>
axios.post('/calculate', {data}),
);
if(certainConditionMet) {
try {
const data = await mutateAsync('calculate-data', myData);
console.log(data)
} catch (error) {
console.error(error)
} finally {
console.log('settled')
}
}
...
return config;
}); // end of interceptor
At runtime, I get warning:
WARN Possible Unhandled Promise Rejection (id: 0):
TypeError: undefined is not an object (evaluating '_context2.t0.response.data')
_callee2$@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:115077:84
tryCatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:28928:23
invoke@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:29104:32
The warning on simulator is like:
in the interceptor code above, if I comment out other code only leave the useMutation() statement, the same warning throws. I mean in the interceptor if I only have:
axios.interceptors.request.use(async (config) => {
// firstly I get data from local storage
const myData = {value: 'foo'};
// I prepare the mutateAsync
const {mutateAsync} = useMutation((data) =>
axios.post('/calculate', {data}),
);
return config;
}); // end of interceptor
The same warning throws at runtime, it means the warning comes from the above useMutation(...) code, but why I get the warning with above useMutation statement in the request interceptor?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I upgraded react-query to version :
"react-query": "^3.5.11",
Based on the documentation, in react-query version 3 there is a
mutateAsync
return value introduced whenuseMutation(...)
.In my react-native project, I use Axios for API call. I use the Axios provided interceptor to intercept each request. In the interceptor I would like to
useMutation()
to send a POST request like the following code shows:At runtime, I get warning:
The warning on simulator is like:
in the interceptor code above, if I comment out other code only leave the
useMutation()
statement, the same warning throws. I mean in the interceptor if I only have:The same warning throws at runtime, it means the warning comes from the above useMutation(...) code, but why I get the warning with above
useMutation
statement in the request interceptor?Beta Was this translation helpful? Give feedback.
All reactions