use effect and state to disable clear button: prevent hydration errors if the field is initialized differently in the client
This commit is contained in:
parent
820ea90267
commit
9c6e98b47b
|
@ -524,6 +524,11 @@ function InputInner ({
|
||||||
|
|
||||||
const remaining = maxLength && maxLength - (field.value || '').length
|
const remaining = maxLength && maxLength - (field.value || '').length
|
||||||
|
|
||||||
|
const [showClearButton, setShowClearButton] = useState(clear)
|
||||||
|
useEffect(() => {
|
||||||
|
setShowClearButton(clear && field.value)
|
||||||
|
}, [field.value])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<InputGroup hasValidation className={inputGroupClassName}>
|
<InputGroup hasValidation className={inputGroupClassName}>
|
||||||
|
@ -538,7 +543,7 @@ function InputInner ({
|
||||||
isInvalid={invalid}
|
isInvalid={invalid}
|
||||||
isValid={showValid && meta.initialValue !== meta.value && meta.touched && !meta.error}
|
isValid={showValid && meta.initialValue !== meta.value && meta.touched && !meta.error}
|
||||||
/>
|
/>
|
||||||
{(clear && field.value) &&
|
{showClearButton &&
|
||||||
<Button
|
<Button
|
||||||
variant={null}
|
variant={null}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
|
|
Loading…
Reference in New Issue