aboutsummaryrefslogtreecommitdiff
path: root/src/hooks/useNavigate.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-08-08 09:42:16 +0300
committereug-vs <eug-vs@keemail.me>2020-08-08 09:42:16 +0300
commit6a0b6ec911c39989a1af4322e2a32d75fddbb274 (patch)
treed6b186e7dac66cf2ba59ad1bc306719b11bf7f87 /src/hooks/useNavigate.tsx
parent10e146ef0215d41527f0466b0e139a6805b96540 (diff)
downloadwhich-ui-6a0b6ec911c39989a1af4322e2a32d75fddbb274.tar.gz
feat: complete router navigation
Diffstat (limited to 'src/hooks/useNavigate.tsx')
-rw-r--r--src/hooks/useNavigate.tsx42
1 files changed, 0 insertions, 42 deletions
diff --git a/src/hooks/useNavigate.tsx b/src/hooks/useNavigate.tsx
deleted file mode 100644
index d1a433d..0000000
--- a/src/hooks/useNavigate.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-import React, { useState, useContext, createContext } from 'react';
-
-export interface Page {
- prefix: string;
- id?: string;
-}
-
-interface ContextType {
- page: Page;
- setPage: (page: Page) => void;
- navigate: (prefix: string, id?: string) => void;
-}
-
-const landingPage = { prefix: 'home' };
-
-const context = createContext<ContextType>({
- page: landingPage,
- setPage: () => {},
- navigate: () => {}
-});
-
-const useProvideNavigation = () => {
- const [page, setPage] = useState<Page>(landingPage);
-
- const navigate: ContextType['navigate'] = (prefix, id?) => {
- setPage({ prefix, id });
- window.scrollTo(0, 0);
- };
-
- return { page, setPage, navigate };
-};
-
-export const NavigationProvider: React.FC = ({ children }) => {
- const navigation = useProvideNavigation();
- const { Provider } = context;
- return <Provider value={navigation}>{children}</Provider>;
-};
-
-export const useNavigate = (): ContextType => {
- return useContext(context);
-};
-