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:
691 bytes
|
Rev | Line | |
---|
[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | var react_1 = require("react");
|
---|
| 4 | var useFirstMountState_1 = require("./useFirstMountState");
|
---|
| 5 | var strictEquals = function (prev, next) { return prev === next; };
|
---|
| 6 | function usePreviousDistinct(value, compare) {
|
---|
| 7 | if (compare === void 0) { compare = strictEquals; }
|
---|
| 8 | var prevRef = react_1.useRef();
|
---|
| 9 | var curRef = react_1.useRef(value);
|
---|
| 10 | var isFirstMount = useFirstMountState_1.useFirstMountState();
|
---|
| 11 | if (!isFirstMount && !compare(curRef.current, value)) {
|
---|
| 12 | prevRef.current = curRef.current;
|
---|
| 13 | curRef.current = value;
|
---|
| 14 | }
|
---|
| 15 | return prevRef.current;
|
---|
| 16 | }
|
---|
| 17 | exports.default = usePreviousDistinct;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.