useFlamegraphPreferences.ts 823 B

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