UNPKG

@selfcommunity/react-core

Version:

React Core Components useful for integrating UI Community components (react-ui).

24 lines (23 loc) 615 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = require("react"); /** * Get previous props value with React Hooks * @param value * * Usage: * import {usePreviousValue} from '@selfcommunity/react-core'; * * const MyComponent = ({ count }) => { * const prevCount = usePreviousValue(count); * return (<div> {count} | {prevCount}</div>); * } */ const usePreviousValue = (value) => { const ref = (0, react_1.useRef)(); (0, react_1.useEffect)(() => { ref.current = value; }); return ref.current; }; exports.default = usePreviousValue;