From 3318a2c766dad7373efe930c9f9145245b0f4a17 Mon Sep 17 00:00:00 2001 From: Mark Eklund Date: Sat, 16 Jul 2022 12:21:16 -0400 Subject: [PATCH] Move useMemo out of an if --- src/HighlightWithinTextarea.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/HighlightWithinTextarea.tsx b/src/HighlightWithinTextarea.tsx index b62d013..48312e3 100644 --- a/src/HighlightWithinTextarea.tsx +++ b/src/HighlightWithinTextarea.tsx @@ -108,12 +108,12 @@ const HighlightWithinTextarea = React.forwardRef( const contentState = editorState.getCurrentContent(); let decorator; - if (highlight) { - decorator = useMemo( - () => createDecorator(contentState, highlight as Highlight, value), - [contentState, highlight, value] - ); - } + decorator = useMemo( + () => + highlight && + createDecorator(contentState, highlight as Highlight, value), + [contentState, highlight, value] + ); editorState = EditorState.set(editorState, { decorator: decorator, @@ -149,7 +149,7 @@ const HighlightWithinTextarea = React.forwardRef( delete newProps.selection; delete newProps.placeholder; delete newProps.onChange; - delete (newProps as {value?: string}).value; + delete (newProps as { value?: string }).value; return (