'Detect page reload on react (the history keeps the url before the reload action)
I'm having some issues with a tab component in multiple instances inside the same page. I would like some sort of page reload detection to be able of clearing the history. This is my prefilter function and click tab function when someone reloads:
const onTabClick = (tabId, tabHead) => {
const state = !tabSelected;
toggleTabSelected(tabId);
history.push(
`${location.pathname}?tab=${tabId}`,
{
shallow: true,
}
);
};
const preSelect = () => {
if (values.tab) {
let queryString = values.tab.toString();
let selectedTab = Number(queryString) - 1;
const allTabs = props.tabs;
toggleTabSelected(queryString);
toggleMobSelected(queryString);
} else {
toggleTabSelected(firstTab);
toggleMobSelected(firstTab);
}
};
useEffect(() => {
preSelect();
}, [tabSelected, mobSelected]);
The problem with this code is when I reload the page, the history keeps the url of the last tab that was open, while I would like to reset it. Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
