flipper-plugin
Version:
Flipper Desktop plugin SDK and components
25 lines • 790 B
JavaScript
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLatestRef = void 0;
const react_1 = require("react");
/**
* Creates a ref object that is always synced from the value passed in.
*/
function useLatestRef(latest) {
const latestRef = (0, react_1.useRef)(latest);
// TODO: sync eagerly (in render) or late? Introduce a `syncEarly` flag as second arg
(0, react_1.useEffect)(() => {
latestRef.current = latest;
}, [latest]);
return latestRef;
}
exports.useLatestRef = useLatestRef;
//# sourceMappingURL=useLatestRef.js.map
;