useFlamegraphTheme.ts 668 B

123456789101112131415161718192021222324252627
  1. import {useContext} from 'react';
  2. import {FlamegraphTheme} from './flamegraphTheme';
  3. import {
  4. FlamegraphThemeContext,
  5. FlamegraphThemeMutationContext,
  6. } from './flamegraphThemeProvider';
  7. export function useFlamegraphTheme(): FlamegraphTheme {
  8. const ctx = useContext(FlamegraphThemeContext);
  9. if (!ctx) {
  10. throw new Error('useFlamegraphTheme was called outside of FlamegraphThemeProvider');
  11. }
  12. return ctx;
  13. }
  14. export function useMutateFlamegraphTheme() {
  15. const ctx = useContext(FlamegraphThemeMutationContext);
  16. if (!ctx) {
  17. throw new Error(
  18. 'useMutateFlamegraphTheme was called outside of FlamegraphThemeProvider'
  19. );
  20. }
  21. return ctx;
  22. }