useFlamegraphProfiles.tsx 788 B

1234567891011121314151617181920212223242526272829
  1. import {useContext} from 'react';
  2. import {
  3. FlamegraphStateContext,
  4. FlamegraphStateContextValue,
  5. } from './flamegraphStateProvider/index';
  6. export function useFlamegraphProfiles(): [
  7. FlamegraphStateContextValue[0]['profiles'],
  8. FlamegraphStateContextValue[1]
  9. ] {
  10. const context = useContext(FlamegraphStateContext);
  11. if (context === null) {
  12. throw new Error('useFlamegraphProfiles called outside of FlamegraphStateProvider');
  13. }
  14. return [context[0].profiles, context[1]];
  15. }
  16. export function useFlamegraphProfilesValue(): FlamegraphStateContextValue[0]['profiles'] {
  17. const context = useContext(FlamegraphStateContext);
  18. if (context === null) {
  19. throw new Error('useFlamegraphProfiles called outside of FlamegraphStateProvider');
  20. }
  21. return context[0].profiles;
  22. }