{"id":13400645,"url":"https://github.com/duskload/react-device-detect","last_synced_at":"2025-05-13T20:15:45.334Z","repository":{"id":37431115,"uuid":"107273802","full_name":"duskload/react-device-detect","owner":"duskload","description":"Detect device, and render view according to detected device type.","archived":false,"fork":false,"pushed_at":"2024-07-03T00:31:27.000Z","size":1116,"stargazers_count":2867,"open_issues_count":72,"forks_count":158,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-28T10:57:45.333Z","etag":null,"topics":["detect","device","javascript","mobile","user-agent","useragent"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/duskload.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-17T13:39:44.000Z","updated_at":"2025-04-26T08:34:41.000Z","dependencies_parsed_at":"2024-11-25T16:08:29.187Z","dependency_job_id":"35b7d55b-7f78-494b-8da4-4c228d2a15e7","html_url":"https://github.com/duskload/react-device-detect","commit_stats":{"total_commits":137,"total_committers":33,"mean_commits":4.151515151515151,"dds":0.7372262773722628,"last_synced_commit":"44d68ccd26e4b3b73adce2744f2d745bae2d42f3"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duskload%2Freact-device-detect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duskload%2Freact-device-detect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duskload%2Freact-device-detect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duskload%2Freact-device-detect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/duskload","download_url":"https://codeload.github.com/duskload/react-device-detect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254020639,"owners_count":22000756,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["detect","device","javascript","mobile","user-agent","useragent"],"created_at":"2024-07-30T19:00:54.215Z","updated_at":"2025-05-13T20:15:45.317Z","avatar_url":"https://github.com/duskload.png","language":"JavaScript","readme":"## react-device-detect\n\n![npm](https://img.shields.io/npm/dm/react-device-detect?label=npm%20downloads)\n\nDetect device, and render view according to the detected device type.\n\n## Installation\n\nTo install, you can use npm or yarn:\n\n```\nnpm install react-device-detect --save\n\nor\n\nyarn add react-device-detect\n```\n\n## When to use this library\n\nThis library uses a technique called [user agent sniffing](https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent) to detect device information. That means it works by examining the [User Agent string](https://en.wikipedia.org/wiki/User_agent) given by a browser and comparing it to a list of browser and device names it knows about. This technique works, but [has drawbacks](https://css-tricks.com/browser-detection-is-bad/) and may or may not be the right approach, depending on what you're trying to achieve. If you need to detect a specific browser type (e.g. Chrome, Safari, Internet Explorer) or specific category of device (e.g. all iPods), this library can do that. If you just want your React app to behave differently or look different on mobiles in general, [CSS `@media` queries](https://developer.mozilla.org/en-US/docs/Web/CSS/@media) and [`matchMedia`](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia) are probably what you want. There are many libraries that can help with using `@media` queries and `matchMedia` in React projects, such as [react-responsive](https://www.npmjs.com/package/react-responsive) and [@react-hook/media-query](https://www.npmjs.com/package/@react-hook/media-query).\n\n## API\n\n- [Hooks, SSR and utilities](docs/api.md)\n- [Selectors](docs/selectors.md)\n- [Views](docs/views.md)\n\n## Usage\n\nExample:\n\n```javascript\nimport { BrowserView, MobileView, isBrowser, isMobile } from 'react-device-detect';\n```\n\n```html\n\u003cBrowserView\u003e\n  \u003ch1\u003eThis is rendered only in browser\u003c/h1\u003e\n\u003c/BrowserView\u003e\n\u003cMobileView\u003e\n  \u003ch1\u003eThis is rendered only on mobile\u003c/h1\u003e\n\u003c/MobileView\u003e\n```\n\nif you don't need a view, you can use `isMobile` for conditional rendering\n\n```javascript\nimport {isMobile} from 'react-device-detect';\n\nfunction App() {\n  renderContent = () =\u003e {\n    if (isMobile) {\n      return \u003cdiv\u003e This content is available only on mobile\u003c/div\u003e\n    }\n    return \u003cdiv\u003e ...content \u003c/div\u003e\n  }\n\n  render() {\n    return this.renderContent();\n  }\n}\n```\n\nIf you want to leave a message to a specific browser (e.g IE), you can use `isIE` selector\n\n```javascript\nimport { isIE } from 'react-device-detect';\n\nfunction App() {\n  render() {\n    if (isIE) return \u003cdiv\u003e IE is not supported. Download Chrome/Opera/Firefox \u003c/div\u003e\n    return (\n      \u003cdiv\u003e...content\u003c/div\u003e\n    )\n  }\n}\n```\n\nIf you want to render a view on a specific device and with a specific condition:\n\n```javascript\nimport { browserName, CustomView } from 'react-device-detect';\n\nfunction App() {\n  render() {\n    return (\n      \u003cCustomView condition={browserName === \"Chrome\"}\u003e\n        \u003cdiv\u003e...content\u003c/div\u003e\n      \u003c/CustomView\u003e\n    )\n  }\n}\n```\n\n## Style the view\n\nYou can style a view component by passing class to the `className` prop\n\n```html\n\u003cBrowserView className=\"custom-class\"\u003e\n  \u003cp\u003eView content\u003c/p\u003e\n\u003c/BrowserView\u003e\n```\n\nor you can pass inline styles to `style` prop\n\n```javascript\nconst styles = {\n  background: 'red',\n  fontSize: '24px',\n  lineHeight: '2',\n};\n```\n\n```html\n\u003cBrowserView style={styles}\u003e\n  \u003cp\u003eView content\u003c/p\u003e\n\u003c/BrowserView\u003e\n```\n\n### Testing\n\n```js\nimport * as rdd from 'react-device-detect';\n\nrdd.isMobile = true;\n\n// use in tests\n```\n\n## License\n\nMIT\n","funding_links":[],"categories":["Uncategorized","JavaScript","React [🔝](#readme)"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduskload%2Freact-device-detect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fduskload%2Freact-device-detect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduskload%2Freact-device-detect/lists"}