routingContext.tsx 574 B

1234567891011121314151617181920212223242526
  1. import {createContext, useContext} from 'react';
  2. interface RoutingContextValue {
  3. baseURL: string;
  4. }
  5. const DEFAULT_VALUE = {
  6. baseURL: '/starfish',
  7. };
  8. const RoutingContext = createContext<RoutingContextValue>(DEFAULT_VALUE);
  9. interface Props {
  10. children: React.ReactNode;
  11. value?: RoutingContextValue;
  12. }
  13. export const useRoutingContext = () => useContext(RoutingContext);
  14. export function RoutingContextProvider({value, children}: Props) {
  15. return (
  16. <RoutingContext.Provider value={value ?? DEFAULT_VALUE}>
  17. {children}
  18. </RoutingContext.Provider>
  19. );
  20. }