useFlamegraphSearch.ts 771 B

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