Here is the simple scenario, I am struggling with
apicontainer.js
import mockApi from './mock-api';
import realApi from './api';
function getApi() {
return Cookies.get('isMock') ? mockApi: realApi;
}
let api = getApi();
export function changeApi() {
api = getApi();
}
export default api
somepage.js
import api from './path-to/apicontainer';
After the application gets loaded, If set/remove cookie and call changeApi
method, will it change the reference dynamically and returns the right api or Is there a better solution?