diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-08-08 11:28:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-08 11:28:07 +0300 |
commit | 70d533d2bcbaa689d3de6ecb532997cd68a7a842 (patch) | |
tree | 0199ab8a91f3e1bd5df0865c10695dde20a5303f /src/hooks/useNavigate.tsx | |
parent | 84eaed2f29ac370eea7c4a7ded6fb3d4661c9679 (diff) | |
parent | 104c658fc411536e09931191721411de448f964f (diff) | |
download | which-ui-70d533d2bcbaa689d3de6ecb532997cd68a7a842.tar.gz |
Merge pull request #72 from which-ecosystem/feat/routing
Add basic routing
Diffstat (limited to 'src/hooks/useNavigate.tsx')
-rw-r--r-- | src/hooks/useNavigate.tsx | 42 |
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); -}; - |