From 20c03ad40a33dad58f21a5ee01c7efa463b3d3f2 Mon Sep 17 00:00:00 2001 From: Dmitriy Kovalenko Date: Mon, 24 Jun 2019 11:06:50 +0300 Subject: [PATCH 1/2] [#1126] Fix rerendering loop --- lib/src/_shared/hooks/usePickerState.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/_shared/hooks/usePickerState.ts b/lib/src/_shared/hooks/usePickerState.ts index e8e7ec938e3425..019c2e76a4a01e 100644 --- a/lib/src/_shared/hooks/usePickerState.ts +++ b/lib/src/_shared/hooks/usePickerState.ts @@ -4,25 +4,25 @@ import { MaterialUiPickersDate } from '../..'; import { useOpenState } from './useOpenState'; import { BasePickerProps } from '../../typings/BasePicker'; import { getDisplayDate, validate } from '../../_helpers/text-field-helper'; -import { useCallback, useDebugValue, useEffect, useMemo, useState } from 'react'; +import { useCallback, useDebugValue, useEffect, useMemo, useState, useRef } from 'react'; export interface StateHookOptions { getDefaultFormat: () => string; } -const valueToDate = ( +const useValueToDate = ( utils: IUtils, { value, initialFocusedDate }: BasePickerProps ) => { - const initialDate = value || initialFocusedDate || utils.date(); - const date = utils.date(initialDate); + const nowRef = useRef(utils.date()); + const date = utils.date(value || initialFocusedDate || nowRef.current); - return date && utils.isValid(date) ? date : utils.date(); + return date && utils.isValid(date) ? date : nowRef.current; }; function useDateValues(props: BasePickerProps, options: StateHookOptions) { const utils = useUtils(); - const date = valueToDate(utils, props); + const date = useValueToDate(utils, props); const format = props.format || options.getDefaultFormat(); return { date, format }; From 0abd0ea45122ec897c0a3d889cff765756fd14af Mon Sep 17 00:00:00 2001 From: Dmitriy Kovalenko Date: Mon, 24 Jun 2019 11:14:20 +0300 Subject: [PATCH 2/2] Fix invalidLabel prop-type warning --- lib/src/Picker/WrappedKeyboardPicker.tsx | 1 + lib/src/Picker/WrappedPurePicker.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/src/Picker/WrappedKeyboardPicker.tsx b/lib/src/Picker/WrappedKeyboardPicker.tsx index e64dd74082ce9e..eddd5276998074 100644 --- a/lib/src/Picker/WrappedKeyboardPicker.tsx +++ b/lib/src/Picker/WrappedKeyboardPicker.tsx @@ -61,6 +61,7 @@ export function makeKeyboardPicker({ value, dateRangeIcon, emptyLabel, + invalidLabel, timeIcon, variant, disableToolbar, diff --git a/lib/src/Picker/WrappedPurePicker.tsx b/lib/src/Picker/WrappedPurePicker.tsx index ad2af46e825b63..ce28c64efaa069 100644 --- a/lib/src/Picker/WrappedPurePicker.tsx +++ b/lib/src/Picker/WrappedPurePicker.tsx @@ -51,6 +51,7 @@ export function makePurePicker({ shouldDisableDate, dateRangeIcon, emptyLabel, + invalidLabel, timeIcon, value, variant,