-
Notifications
You must be signed in to change notification settings - Fork 0
DeviceInfoProvider.jsx
Nikita Mogilevskii edited this page Feb 18, 2025
·
1 revision
The DeviceInfoProvider.jsx file provides device-specific information to the React application. It uses React Context API to share device info across components.
-
React,createContext,useContext,useState,useEffect: Core React utilities.
- DeviceInfoContext: Context for sharing device information.
- useDeviceInfo: Custom hook to access the context.
Manages the following device information:
-
ip: Public IP address. -
deviceType:mobileordesktop. -
orientation:portraitorlandscape. -
browserModel: Browser type (e.g., Chrome, Firefox). -
operatingSystem: OS type (e.g., Windows, macOS, Linux).
- Fetches the IP address from
https://api.ipify.org?format=json. - Handles errors gracefully if the fetch fails.
- Uses
navigator.userAgentto detect device type and browser. - Uses
navigator.platformto identify the operating system.
- Checks window dimensions to determine orientation.
- Updates orientation on
resizeevents.
- Mount: Fetches IP and sets initial device info.
- Resize: Updates orientation on window resize.
- Unmount: Cleans up resize event listener.
To use the DeviceInfoProvider:
import { useDeviceInfo } from './services/DeviceInfoProvider';
const deviceInfo = useDeviceInfo();
console.log(deviceInfo);Thank you for visiting the webOS Wiki! We hope this documentation helps you navigate, understand, and extend the project effectively.
Contact: Reach out via LinkedIn.
Happy coding! 🚀