Attach Authorization header for all axios requests

There are multiple ways to achieve this. Here, I have explained the two most common approaches. 1. You can use axios interceptors to intercept any requests and add authorization headers. // Add a request interceptor axios.interceptors.request.use(function (config) { const token = store.getState().session.token; config.headers.Authorization = token; return config; }); 2. From the documentation of axios you … Read more

How to overcome the CORS issue in ReactJS

the simplest way what I found from a tutorial of “TraversyMedia” is that just use https://cors-anywhere.herokuapp.com in ‘axios’ or ‘fetch’ api https://cors-anywhere.herokuapp.com/{type_your_url_here} e.g. axios.get(`https://cors-anywhere.herokuapp.com/https://www.api.com/`) and in your case edit url as url: ‘https://cors-anywhere.herokuapp.com/https://www.api.com’,

Deep copy in ES6 using the spread syntax

Use JSON for deep copy var newObject = JSON.parse(JSON.stringify(oldObject)) var oldObject = { name: ‘A’, address: { street: ‘Station Road’, city: ‘Pune’ } } var newObject = JSON.parse(JSON.stringify(oldObject)); newObject.address.city = ‘Delhi’; console.log(‘newObject’); console.log(newObject); console.log(‘oldObject’); console.log(oldObject);