flipper-plugin
Version:
Flipper Desktop plugin SDK and components
29 lines • 1.36 kB
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.useAssertStableRef = void 0;
const flipper_common_1 = require("flipper-common");
const react_1 = require("react");
/**
* This hook will throw in development builds if the value passed in is unstable.
* Use this if to make sure consumers aren't creating or changing certain props over time
* (intentionally or accidentally)
*/
exports.useAssertStableRef = !(0, flipper_common_1.isProduction)()
? function useAssertStableRef(value, prop) {
const ref = (0, react_1.useRef)(value);
if (ref.current !== value) {
throw new Error(`[useAssertStableRef] An unstable reference was passed to this component as property '${prop}'. For optimization purposes we expect that this prop doesn't change over time. You might want to create the value passed to this prop outside the render closure, store it in useCallback / useMemo / useState, or set a key on the parent component. Prev value: ${ref.current}. New value: ${value}`);
}
}
: function (_value, _prop) {
// no-op
};
//# sourceMappingURL=useAssertStableRef.js.map
;