UNPKG

@mui/x-date-pickers

Version:

The community edition of the MUI X Date and Time Picker components.

29 lines 1.06 kB
import * as React from 'react'; import useEventCallback from '@mui/utils/useEventCallback'; /** * Generate the props to pass to the hidden input element of the field. * @param {UseFieldHiddenInputPropsParameters} parameters The parameters of the hook. * @returns {UseFieldHiddenInputPropsReturnValue} The props to forward to the hidden input element of the field. */ export function useFieldHiddenInputProps(parameters) { const { manager: { internal_fieldValueManager: fieldValueManager }, stateResponse: { // States and derived states areAllSectionsEmpty, state, // Methods to update the states updateValueFromValueStr } } = parameters; const handleChange = useEventCallback(event => { updateValueFromValueStr(event.target.value); }); const valueStr = React.useMemo(() => areAllSectionsEmpty ? '' : fieldValueManager.getHiddenInputValueFromSections(state.sections), [areAllSectionsEmpty, state.sections, fieldValueManager]); return { value: valueStr, onChange: handleChange }; }