diff --git a/change/@fluentui-react-fcd794a8-7856-4526-a422-5594334da599.json b/change/@fluentui-react-fcd794a8-7856-4526-a422-5594334da599.json new file mode 100644 index 00000000000000..923f228bd94a79 --- /dev/null +++ b/change/@fluentui-react-fcd794a8-7856-4526-a422-5594334da599.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "In Timepicker intialValue const used the useConst hook which does not update the initial value of the timepicker if the TimePicker receive updated date via props", + "packageName": "@fluentui/react", + "email": "harminder_Sethi@outlook.com", + "dependentChangeType": "patch" +} diff --git a/packages/react/src/components/TimePicker/TimePicker.tsx b/packages/react/src/components/TimePicker/TimePicker.tsx index 833e5dd66252ad..2e4d281a29caec 100644 --- a/packages/react/src/components/TimePicker/TimePicker.tsx +++ b/packages/react/src/components/TimePicker/TimePicker.tsx @@ -1,5 +1,4 @@ import * as React from 'react'; -import { useConst } from '@fluentui/react-hooks'; import { KeyCodes } from '../../Utilities'; import { TimeConstants, @@ -8,6 +7,7 @@ import { ceilMinuteToIncrement, getDateFromTimeSelection, } from '@fluentui/date-time-utilities'; +import { useControllableValue } from '@fluentui/react-hooks'; import { ComboBox } from '../../ComboBox'; import type { IComboBox, IComboBoxOption } from '../../ComboBox'; import type { ITimePickerProps, ITimeRange, ITimePickerStrings } from './TimePicker.types'; @@ -52,8 +52,8 @@ export const TimePicker: React.FunctionComponent = ({ const optionsCount = getDropdownOptionsCount(increments, timeRange); - const initialValue = useConst(defaultValue || new Date()); - const baseDate: Date = React.useMemo(() => generateBaseDate(increments, timeRange, initialValue), [ + const [initialValue] = useControllableValue(defaultValue, new Date()); + const baseDate: Date = React.useMemo(() => generateBaseDate(increments, timeRange, initialValue as Date), [ increments, timeRange, initialValue,