https://github.com/masaok/react-hook-accelerometer
React Hook into Accelerometer Sensor (includes the acceleration of gravity)
https://github.com/masaok/react-hook-accelerometer
accelerometer capstone hook react
Last synced: 2 months ago
JSON representation
React Hook into Accelerometer Sensor (includes the acceleration of gravity)
- Host: GitHub
- URL: https://github.com/masaok/react-hook-accelerometer
- Owner: masaok
- License: lgpl-3.0
- Created: 2022-04-04T03:40:00.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-01T13:11:36.000Z (about 4 years ago)
- Last Synced: 2025-01-29T17:13:51.211Z (over 1 year ago)
- Topics: accelerometer, capstone, hook, react
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/react-hook-accelerometer
- Size: 85 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
The Accelerometer sensor includes the force of gravity, unlike the Linear Acceleration sensor.
## Installation
Using `npm`:
```sh
npm install --save react-hook-accelerometer
```
Using `yarn`:
```sh
yarn add react-hook-accelerometer
```
## Usage
```jsx
import React from "react";
import useAccelerometer from "react-hook-accelerometer";
const ComponentWithAccelerometer = () => {
const sensor = useAccelerometer();
return !sensor.error ? (
- X: {sensor.x}
- Y: {sensor.y}
- Z: {sensor.z}
) : (
No Accelerometer, sorry.
);
};
```
### Using `SensorOptions`
If you want to use this feature, simply provide `useAccelerometer` with a `SensorOptions` object:
```jsx
const sensor = useAccelerometer({
frequency: 60, // cycles per second
});
```
## Notes
Access to data from the Accelerometer API needs user permission.
## Caveats
Accelerometer API is available only in secure contexts (only using HTTPS).
## Credits
Credit to [Bence A. Tóth](https://github.com/bence-toth) for his original hook code for [Geolocation](https://www.npmjs.com/package/react-hook-geolocation).
## License
LGPL-3.0