asyncSDKIntegrationProvider.tsx 736 B

1234567891011121314151617181920212223242526272829
  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. type Context = {
  6. setState: React.Dispatch<React.SetStateAction<State>>;
  7. state: State;
  8. };
  9. const context = createContext<Context>({
  10. setState: () => {},
  11. state: {},
  12. });
  13. export function AsyncSDKIntegrationContextProvider({
  14. children,
  15. }: {
  16. children: React.ReactNode;
  17. }) {
  18. const [state, setState] = useState<State>({});
  19. return <context.Provider value={{setState, state}}>{children}</context.Provider>;
  20. }
  21. export default function useAsyncSDKIntegrationStore(): Context {
  22. return useContext(context);
  23. }