use-is-mobile.ts 478 B

12345678910111213141516171819
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { useState, useEffect } from 'react';
  6. export const useIsMobile = (): boolean => {
  7. const [isMobile, setIsMobile] = useState<boolean>(false);
  8. useEffect(() => {
  9. const checkIsMobile = (): boolean =>
  10. /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
  11. setIsMobile(checkIsMobile());
  12. }, []);
  13. return isMobile;
  14. };