teableio/teable

View on GitHub
apps/nextjs-app/src/features/app/utils/get-mod-key-str.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { useEffect, useState } from 'react';

export function useModKeyStr() {
  const [modKeyStr, setModKeyStr] = useState('');
  useEffect(() => {
    if (typeof navigator !== 'undefined') {
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      const platform = navigator.platform || (navigator as any).userAgentData?.platform || '';
      const key = /^Mac/i.test(platform) ? '⌘' : 'Ctrl';
      setModKeyStr(key);
    }
  }, []);
  return modKeyStr;
}