main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
745 bytes
|
Line | |
---|
1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | var tslib_1 = require("tslib");
|
---|
4 | var react_1 = require("react");
|
---|
5 | var useUnmount_1 = tslib_1.__importDefault(require("./useUnmount"));
|
---|
6 | var useRafState = function (initialState) {
|
---|
7 | var frame = react_1.useRef(0);
|
---|
8 | var _a = react_1.useState(initialState), state = _a[0], setState = _a[1];
|
---|
9 | var setRafState = react_1.useCallback(function (value) {
|
---|
10 | cancelAnimationFrame(frame.current);
|
---|
11 | frame.current = requestAnimationFrame(function () {
|
---|
12 | setState(value);
|
---|
13 | });
|
---|
14 | }, []);
|
---|
15 | useUnmount_1.default(function () {
|
---|
16 | cancelAnimationFrame(frame.current);
|
---|
17 | });
|
---|
18 | return [state, setRafState];
|
---|
19 | };
|
---|
20 | exports.default = useRafState;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.