https://github.com/webbestmaster/react-system-hook
Several react hooks\helpers to work with device's screen
https://github.com/webbestmaster/react-system-hook
Last synced: 2 months ago
JSON representation
Several react hooks\helpers to work with device's screen
- Host: GitHub
- URL: https://github.com/webbestmaster/react-system-hook
- Owner: webbestmaster
- License: mit
- Created: 2021-08-02T13:27:20.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-24T21:56:16.000Z (10 months ago)
- Last Synced: 2024-11-06T21:06:43.335Z (8 months ago)
- Language: TypeScript
- Homepage:
- Size: 219 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# React System Hook
[](https://github.com/webbestmaster/react-system-hook/blob/master/license)
[](https://codecov.io/gh/webbestmaster/react-system-hook)
[](https://www.npmjs.com/package/react-system-hook)
[](https://snyk.io/test/github/webbestmaster/react-system-hook)
[](https://libraries.io/npm/react-system-hook)
[](https://bundlephobia.com/package/react-system-hook)
[](https://nodejs.org/en/docs)
[](https://github.com/webbestmaster/react-system-hook/actions/workflows/github-ci.yml)
[](https://github.com/webbestmaster/react-system-hook/actions/workflows/github-ci.yml)
[](https://www.typescriptlang.org)
[](https://github.com/webbestmaster/react-system-hook)
[](https://www.codefactor.io/repository/github/webbestmaster/react-system-hook)
[](https://packagequality.com/#?package=react-system-hook)
[](https://github.com/webbestmaster/react-system-hook)Several hooks\helpers to work with device's screen.
## Install
```bash
npm i react-system-hook
```## Usage
```typescript jsx
import {
useSystem,
useScreenHeight,
useScreenWidth,
useScreenSize,
useDocumentVisibility,
ScreenWidthNameEnum,
screenMinWidth, // object: Record
getScreenName, // (screenWidth: number) => ScreenWidthNameEnum
getDocumentIsVisible, // () => boolean, it always returns `false` for server side rendering
} from 'react-system-hook';export function ExampleApp(): JSX.Element {
const {
screenInfo,
isBrowser, // true if running in browser, false for SSR
} = useSystem();const {
devicePixelRatio, // number, default: 2, usually is 2 for smartphones
isLandscape, // true if width > height
isMobile, // screen width < 768
isPortrait, // opposite for isLandscape
name, // ScreenWidthNameEnum, relative from screen width: 'desktop', 'mobile' or 'tablet'
isTablet, // screen width < 1024 and width >= 768
isDesktop, // screen width >= 1024
} = screenInfo;const {
height, // number, default: 768
width, // number, default: 1024
} = useScreenSize();const screenWidth = useScreenWidth(); // number, default: 1024
const screenHeight = useScreenHeight(); // number, default: 768const isDocumentVisible = useDocumentVisibility(); // true or false
return (
screenInfo = {JSON.stringify(screenInfo, null, 4)}
useScreenSize = width: {height}, height: {width}
useScreenWidth = width: {screenWidth}
useScreenHeight = height: {screenHeight}
useDocumentVisibility, is document visible: {isDocumentVisible ? 'yes' : 'no'}
);
}
```## License
See [license](license).