useFlamegraphState.ts 745 B

12345678910111213141516171819202122232425262728
  1. import {useContext} from 'react';
  2. import {
  3. FlamegraphStateDispatch,
  4. FlamegraphStateDispatchContext,
  5. FlamegraphStateValue,
  6. FlamegraphStateValueContext,
  7. } from '../flamegraphStateProvider/flamegraphContext';
  8. export function useFlamegraphState(): FlamegraphStateValue {
  9. const context = useContext(FlamegraphStateValueContext);
  10. if (context === null) {
  11. throw new Error('useFlamegraphState called outside of FlamegraphStateProvider');
  12. }
  13. return context;
  14. }
  15. export function useDispatchFlamegraphState(): FlamegraphStateDispatch {
  16. const context = useContext(FlamegraphStateDispatchContext);
  17. if (context === null) {
  18. throw new Error('useFlamegraphState called outside of FlamegraphStateProvider');
  19. }
  20. return context;
  21. }