npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

useismobile

v1.1.0

Published

A simple React hook that provides a boolean for the screen is mobile or not.

Readme

Coverage Node.js CI version downloads npm bundle size semantic-release MIT Licence

About The Project

useismobile example

useIsMobile is a custom hook for React. It gives you a boolean for the screen is mobile or not.

Built With

Getting Started

Prerequisites

React and ReactDOM must be installed in your project (supports React 16.8+, 17, 18, and 19).

  • npm
    npm install react react-dom

Installation

  1. Install via npm
    npm install useismobile
  2. Install via yarn
    yarn add useismobile

Usage

You can see a basic usage example at codespace demo

Basic Usage

import useIsMobile from 'useismobile'

function App() {
  const isMobile = useIsMobile()

  return (
    <div>
      <h1>Current Device:</h1>
      <p>{isMobile ? 'Mobile Device' : 'Desktop'}</p>
    </div>
  )
}

Custom Screen Size

You can specify a custom breakpoint:

function App() {
  // Consider mobile if screen width is 1024px or less
  const isMobile = useIsMobile(1024)

  return (
    <div>
      <p>{isMobile ? 'Tablet/Mobile' : 'Desktop'}</p>
    </div>
  )
}

Multiple Breakpoints

Use multiple instances for different breakpoints:

function App() {
  const isMobile = useIsMobile(480)
  const isTablet = useIsMobile(1024)

  return (
    <div>
      {isMobile && <MobileNav />}
      {isTablet && !isMobile && <TabletNav />}
      {!isTablet && <DesktopNav />}
    </div>
  )
}

TypeScript Usage

import useIsMobile from 'useismobile';

function App(): JSX.Element {
  const isMobile = useIsMobile(768);

  return <div>{isMobile ? 'Mobile' : 'Desktop'}</div>;
}

With Next.js (SSR)

Since this hook requires window.matchMedia, it won't work on server-side rendering. Use dynamic import:

// Next.js App Router
'use client'
import useIsMobile from 'useismobile'

export default function Page() {
  const isMobile = useIsMobile()
  return <div>{isMobile ? 'Mobile' : 'Desktop'}</div>
}

Or use dynamic import in Pages Router:

import dynamic from 'next/dynamic'

const MobileDetector = dynamic(
  () => import('./MobileDetector').then((mod) => mod.default),
  { ssr: false }
)

export default function Page() {
  return <MobileDetector />
}

Server-Side Rendering (SSR) Support

This hook relies on the browser's window.matchMedia API and therefore only works in client-side environments. If you're using a framework with SSR (Next.js, Gatsby, Remix, etc.), you'll need to handle this appropriately.

Framework-Specific Examples

Next.js (App Router)

'use client'
import useIsMobile from 'useismobile'

export default function Page() {
  const isMobile = useIsMobile()
  // Component will only render on client
}

Next.js (Pages Router)

import { useEffect, useState } from 'react'
import useIsMobile from 'useismobile'

export default function Page() {
  const [isMounted, setIsMounted] = useState(false)
  const isMobile = useIsMobile()

  useEffect(() => {
    setIsMounted(true)
  }, [])

  if (!isMounted) {
    return null // Or a loading state
  }

  return <div>{isMobile ? 'Mobile' : 'Desktop'}</div>
}

Gatsby

import { useEffect, useState } from 'react'
import useIsMobile from 'useismobile'

export default function Page() {
  const [isMounted, setIsMounted] = useState(false)
  const isMobile = useIsMobile()

  useEffect(() => {
    setIsMounted(true)
  }, [])

  if (!isMounted) return null

  return <div>{isMobile ? 'Mobile' : 'Desktop'}</div>
}

Contributing

Any contribution is welcome.

Commitizen standardizes to commit messages, just don't forget to use npm commit command.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Make your changes.
  4. Commit your Changes with npm (npm run commit)
  5. Push to the Branch (git push origin feature/AmazingFeature)
  6. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Tufantunc - @tufant

Project Link: https://github.com/tufantunc/useismobile