@appbuckets/react-ui
Version:
Just Another React UI Framework
42 lines (39 loc) • 978 B
JavaScript
import { __read } from 'tslib';
import * as React from 'react';
/**
* Use this hook to get automatically the color picker value
* and the handler function to attach to color picker.
* Additionally function to force change will be returned
*
* @param initialValue
*/
function useDayPickerValue(initialValue) {
// ----
// Internal State
// ----
var _a = __read(
React.useState(
initialValue !== null && initialValue !== void 0 ? initialValue : null
),
2
),
dayPickerValue = _a[0],
setDayPickerValue = _a[1];
// ----
// Handler
// ----
var handleColorPickerChange = React.useCallback(function (e, props) {
/** If no value, return */
if (!props.date) {
setDayPickerValue(null);
return;
}
/** Parse as date */
return new Date(props.date);
}, []);
// ----
// Hook Return
// ----
return [dayPickerValue, handleColorPickerChange, setDayPickerValue];
}
export { useDayPickerValue };