How to post multiple Axios requests at the same time?

There are three cases via you can achieve your goal. For simultaneous requests with Axios, you can use Axios.all() axios.all([ axios.post(`/my-url`, { myVar: ‘myValue’ }), axios.post(`/my-url2`, { myVar: ‘myValue’ }) ]) .then(axios.spread((data1, data2) => { // output of req. console.log(‘data1’, data1, ‘data2’, data2) })); you can use Promise.allSettled(). The Promise.allSettled() method returns a promise that … Read more

Axios interceptors and asynchronous login

Just use another promise 😀 axios.interceptors.response.use(undefined, function (err) { return new Promise(function (resolve, reject) { if (err.status === 401 && err.config && !err.config.__isRetryRequest) { serviceRefreshLogin( getRefreshToken(), success => { setTokens(success.access_token, success.refresh_token) err.config.__isRetryRequest = true err.config.headers.Authorization = ‘Bearer ‘ + getAccessToken(); axios(err.config).then(resolve, reject); }, error => { console.log(‘Refresh login error: ‘, error); reject(error); } ); } … Read more

React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED)

So the issue was since both the Node dev environment and the Django dev environment were running in separate docker containers, so localhost was referring to the node container, not the bridged network. So the key was to use container links, which are automatically created when using docker-compose, and use that as the hostname. So … Read more

Access to XMLHttpRequest at ‘…’ from origin ‘localhost:3000’ has been blocked by CORS policy

if you are building your rest api in nodejs. Follow the folowing simple steps Stop the Node.js server. npm install cors –save Add following lines to your server.js or index.js var cors = require(‘cors’) app.use(cors()) // Use this after the variable declaration Now try to make your api call on the client side and it … Read more

React and TypeScript—which types for an Axios response?

There is generic get method defined in axios/index.d.ts get<T = never, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>; Example interface User { id: number; firstName: string; } axios.get<User[]>(‘http://localhost:8080/admin/users’) .then(response => { console.log(response.data); setUserList( response.data ); }); I think you are passing list the wrong way to child component. const [users, setUserList] = useState<User[]>([]); <UserList items={users} … Read more