I have Django and react app and I have to show some image as a campaign depending on current url.
On each page, there will be axios get request call to api and react will receive image and show the image on top.
to implement this I created function
let path_name = window.location.pathname;
const CampaignImageFetch = (url) => {
if (!url) return "";
return async () =>
await axios({
method: "get",
url: process.env.REACT_APP_BASE_URL + "campaignpopup" + path_name,
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res;
})
.catch((e) => {
return e;
});
};
To implement this on every page, I have to call this function from every page and will have to load Image component on every page. Is there any way I can implement this without adding the code on every page?