From 9c6e98b47b75868d3ad0aa79210c39b6b7f55d11 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Thu, 24 Oct 2024 16:21:37 +0200 Subject: [PATCH 1/3] use effect and state to disable clear button: prevent hydration errors if the field is initialized differently in the client --- components/form.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/form.js b/components/form.js index 26a956af..221fe52b 100644 --- a/components/form.js +++ b/components/form.js @@ -524,6 +524,11 @@ function InputInner ({ const remaining = maxLength && maxLength - (field.value || '').length + const [showClearButton, setShowClearButton] = useState(clear) + useEffect(() => { + setShowClearButton(clear && field.value) + }, [field.value]) + return ( <> @@ -538,7 +543,7 @@ function InputInner ({ isInvalid={invalid} isValid={showValid && meta.initialValue !== meta.value && meta.touched && !meta.error} /> - {(clear && field.value) && + {showClearButton &&