How to send dunamic key ,value pair while calling POST api in react native

renishdeveloper
0
renishdeveloper
commented 15 days ago

I'm calling the API like this
const data = await axios.post(url, {
key : value,
})
.then(function (response) {
console.warn(response);
})
.catch(function (error) {
console.log('exios erro=>', error);
});
It works fine ,but I want to assign the key from the state ,when i going to write this.state.key instead of key it shows error "Unhandled Promise Rejection".
How to assign the dynamic key while calling API using Axios.

0
manniL
2.9k
manniL
commented 15 days ago
const data = await axios.post(url, {
[this.key] : someValueHere,
})
0
Informations
Question โ€ข Unresolved
#c192 - Created 15 days ago