utils.tsx 769 B

123456789101112131415161718192021222324
  1. import {useMemo} from 'react';
  2. import {usePersistedStoreCategory} from 'sentry/stores/persistedStore';
  3. import {OnboardingState} from './types';
  4. export function usePersistedOnboardingState(): [
  5. OnboardingState | null,
  6. (next: OnboardingState | null) => void
  7. ] {
  8. const [state, setState] = usePersistedStoreCategory('onboarding');
  9. const stableState: [OnboardingState | null, (next: OnboardingState | null) => void] =
  10. useMemo(() => {
  11. const onboardingState = state
  12. ? {
  13. ...state,
  14. platformToProjectIdMap: state.platformToProjectIdMap || {},
  15. selectedPlatforms: state.selectedPlatforms || [],
  16. }
  17. : null;
  18. return [onboardingState, setState];
  19. }, [state, setState]);
  20. return stableState;
  21. }