UNPKG

react-day-picker

Version:

Customizable Date Picker for React

22 lines 856 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useControlledValue = useControlledValue; const react_1 = require("react"); /** * A helper hook for handling controlled and uncontrolled values in a * component's props. * * If the value is uncontrolled, pass `undefined` as `controlledValue` and use * the returned setter to update it. * * If the value is controlled, pass the controlled value as the second argument, * which will always be returned as `value`. * * @template T - The type of the value. */ function useControlledValue(defaultValue, controlledValue) { const [uncontrolledValue, setValue] = (0, react_1.useState)(defaultValue); const value = controlledValue === undefined ? uncontrolledValue : controlledValue; return [value, setValue]; } //# sourceMappingURL=useControlledValue.js.map