react_use_is_mobile
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

useIsMobile

A simple React hook to detect if the current screen size is considered mobile.

Installation

You can install useIsMobile using npm:

npm install react_use_is_mobile

Usage

import React from "react";
import useIsMobile from "react_use_is_mobile";

function MyComponent() {
  const isMobile = useIsMobile();

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

How it works

The useIsMobile hook utilizes the window.innerWidth property to determine if the screen size is less than or equal to 768 pixels, considering it as a mobile view.

It also includes an event listener for the resize event to update the isMobile state dynamically when the screen size changes.

Readme

Keywords

Package Sidebar

Install

npm i react_use_is_mobile

Weekly Downloads

1

Version

1.3.1

License

ISC

Unpacked Size

2.59 kB

Total Files

5

Last publish

Collaborators

  • er_one