replayGroupContext.tsx 821 B

1234567891011121314151617181920212223242526
  1. import {createContext, useContext, useMemo} from 'react';
  2. type Props = {
  3. children: React.ReactNode;
  4. eventId?: string;
  5. groupId?: string;
  6. };
  7. type BreadcrumbCustomizationContextType = Omit<Props, 'children'>;
  8. const ReplayGroupContext = createContext<BreadcrumbCustomizationContextType>({});
  9. /**
  10. * Used when rendering a replay within the context of a group.
  11. * Provides event and group IDs which customize the breadcrumb items
  12. * to highlight the current event and group.
  13. */
  14. export function ReplayGroupContextProvider({children, groupId, eventId}: Props) {
  15. const value = useMemo(() => ({groupId, eventId}), [groupId, eventId]);
  16. return (
  17. <ReplayGroupContext.Provider value={value}>{children}</ReplayGroupContext.Provider>
  18. );
  19. }
  20. export const useReplayGroupContext = () => useContext(ReplayGroupContext);