"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var react_1 = require("react"); var util_1 = require("./misc/util"); var defaultState = { acceleration: { x: null, y: null, z: null, }, accelerationIncludingGravity: { x: null, y: null, z: null, }, rotationRate: { alpha: null, beta: null, gamma: null, }, interval: 16, }; var useMotion = function (initialState) { if (initialState === void 0) { initialState = defaultState; } var _a = react_1.useState(initialState), state = _a[0], setState = _a[1]; react_1.useEffect(function () { var handler = function (event) { var acceleration = event.acceleration, accelerationIncludingGravity = event.accelerationIncludingGravity, rotationRate = event.rotationRate, interval = event.interval; setState({ acceleration: { x: acceleration.x, y: acceleration.y, z: acceleration.z, }, accelerationIncludingGravity: { x: accelerationIncludingGravity.x, y: accelerationIncludingGravity.y, z: accelerationIncludingGravity.z, }, rotationRate: { alpha: rotationRate.alpha, beta: rotationRate.beta, gamma: rotationRate.gamma, }, interval: interval, }); }; util_1.on(window, 'devicemotion', handler); return function () { util_1.off(window, 'devicemotion', handler); }; }, []); return state; }; exports.default = useMotion;