In the following steps, we will create a new custom axios instance that will be used in the HTTP wrapper. Follow these instructions to add the new instance to the application:
- Open the baseFetch.js file in the src/http folder.
- We need to create a new factory function called createAxios to generate a new axios instance each time it's executed:
export function createAxios(options = {}) {
return axios.create({
...options,
});
}
- Now we need to create the localApi constant, the value of which will be the result of the execution of the createAxios factory:
const localApi = createAxios();
- For the JSONPlaceHolder we will create a constant that will be exported, named jsonPlaceholderApi, the value of which will be the execution of the createAxios factory. We will also pass an object as an argument with the baseURL property defined:
export const jsonPlaceholderApi = createAxios({
baseURL: 'https://jsonplaceholder.typicode.com/',
});
- In the...