asyncSDKIntegrationProvider.tsx 703 B

12345678910111213141516171819202122232425262728
  1. import {createContext, useContext, useState} from 'react';
  2. import type {addIntegration} from '@sentry/react';
  3. type Integration = Parameters<typeof addIntegration>[0];
  4. type State = Record<string, Integration | undefined>;
  5. const context = createContext<{
  6. setState: React.Dispatch<React.SetStateAction<State>>;
  7. state: State;
  8. }>({
  9. setState: () => {},
  10. state: {},
  11. });
  12. export function AsyncSDKIntegrationContextProvider({
  13. children,
  14. }: {
  15. children: React.ReactNode;
  16. }) {
  17. const [state, setState] = useState<State>({});
  18. return <context.Provider value={{setState, state}}>{children}</context.Provider>;
  19. }
  20. export default function useAsyncSDKIntegrationStore() {
  21. return useContext(context);
  22. }