main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
592 bytes
|
Line | |
---|
1 | import { useCallback, useRef, useState } from 'react';
|
---|
2 | import useUnmount from './useUnmount';
|
---|
3 | var useRafState = function (initialState) {
|
---|
4 | var frame = useRef(0);
|
---|
5 | var _a = useState(initialState), state = _a[0], setState = _a[1];
|
---|
6 | var setRafState = useCallback(function (value) {
|
---|
7 | cancelAnimationFrame(frame.current);
|
---|
8 | frame.current = requestAnimationFrame(function () {
|
---|
9 | setState(value);
|
---|
10 | });
|
---|
11 | }, []);
|
---|
12 | useUnmount(function () {
|
---|
13 | cancelAnimationFrame(frame.current);
|
---|
14 | });
|
---|
15 | return [state, setRafState];
|
---|
16 | };
|
---|
17 | export default useRafState;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.