From e91a1b09f7a94f77ef6832783340972c89735fc0 Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Fri, 9 Jul 2021 16:24:59 +1000 Subject: [PATCH] CommentInput: stop recreating input --- pkg/interface/src/views/components/CommentInput.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/interface/src/views/components/CommentInput.tsx b/pkg/interface/src/views/components/CommentInput.tsx index 15db3f5f36..e866af0254 100644 --- a/pkg/interface/src/views/components/CommentInput.tsx +++ b/pkg/interface/src/views/components/CommentInput.tsx @@ -11,7 +11,7 @@ import { useField, useFormikContext } from 'formik'; -import React, { useEffect } from 'react'; +import React, { useEffect, useMemo } from 'react'; import * as Yup from 'yup'; import { ShipImage } from './ShipImage'; @@ -68,9 +68,13 @@ function FormikHelper(props: { initialValues: any }) { return null; } +const emptyStr = ''; export default function CommentInput(props: CommentInputProps) { - const initialValues: FormSchema = { comment: props.initial || '' }; + const initialValues: FormSchema = useMemo( + () => ({ comment: props.initial || emptyStr }), + [props.initial]); + const label = props.label || 'Comment'; return (