telegram-tt/src/hooks/useHistoryBack.ts
Alexander Zinchuk c3201cf632 Revert "Better browser history support (#1125)"
This reverts commit 3c19438f1a9f6db9a06dc3b48bd06d062befe0b8.
2021-06-14 22:12:34 +03:00

16 lines
401 B
TypeScript

// This is unsafe and can be not chained as `popstate` event is asynchronous
export default function useHistoryBack(handler: NoneToVoidFunction) {
function handlePopState() {
handler();
}
window.addEventListener('popstate', handlePopState);
window.history.pushState({}, '');
return () => {
window.removeEventListener('popstate', handlePopState);
window.history.back();
};
}