1.1.3 • Published 2 years ago

react-hook-linear-acceleration v1.1.3

Weekly downloads
-
License
LGPL
Repository
github
Last release
2 years ago

A React hook to access data from the Linear Acceleration API.

Installation

Using npm:

npm install --save react-hook-linear-acceleration

Using yarn:

yarn add react-hook-linear-acceleration

Usage

import React from "react";
import useLinearAcceleration from "react-hook-linear-acceleration";

const MyComponent = () => {
  const sensor = useLinearAcceleration();

  return !sensor.error ? (
    <ul>
      <li>X: {sensor.x}</li>
      <li>Y: {sensor.y}</li>
      <li>Z: {sensor.z}</li>
    </ul>
  ) : (
    <p>No linear acceleration, sorry.</p>
  );
};

Notes

Access to data from the Linear Acceleration API needs user permission.

If permission to access Linear Acceleration was previously granted by the user, Linear Acceleration data will be available. If permission to access was not granted previously, the user will be prompted to give permission when the component mounts.

Caveats

Linear Acceleration API is available only in secure contexts (only using HTTPS).

Credits

Credit to Bence A. Tóth for his original hook code for Geolocation.

License

LGPL-3.0