useFlamegraphState.ts 996 B

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