From b57a200e2efc91156bdefd1ba33267bfc0e99966 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Thu, 23 Jan 2025 15:31:13 +0100 Subject: [PATCH] feat: usenavigate function created --- .../capture-core/utils/routing/useNavigate.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/core_modules/capture-core/utils/routing/useNavigate.js diff --git a/src/core_modules/capture-core/utils/routing/useNavigate.js b/src/core_modules/capture-core/utils/routing/useNavigate.js new file mode 100644 index 0000000000..52325ec5b7 --- /dev/null +++ b/src/core_modules/capture-core/utils/routing/useNavigate.js @@ -0,0 +1,18 @@ +// @flow +import { useHistory } from 'react-router-dom'; + +export const useNavigate = () => { + const history = useHistory(); + + const navigate = (path: string, scrollToTop: boolean = true) => + history + .push(path) + .then(() => { + if (scrollToTop) { + window.scrollTo(0, 0); + } + }); + + return { navigate }; +}; +