From 3dc71a8d1fb203d1403c07abcd0fa4e1806f80bb Mon Sep 17 00:00:00 2001 From: whintersnow0 Date: Wed, 15 Oct 2025 19:19:08 +0200 Subject: [PATCH] refactor: remove unnecessary useMemo hooks --- .../src/components/text-field/text-field.tsx | 52 +++++-------------- 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/src/renderer/src/components/text-field/text-field.tsx b/src/renderer/src/components/text-field/text-field.tsx index 1c4d54af..7c0cbb58 100644 --- a/src/renderer/src/components/text-field/text-field.tsx +++ b/src/renderer/src/components/text-field/text-field.tsx @@ -1,16 +1,13 @@ -import React, { useId, useMemo, useState } from "react"; +import React, { useId, useState } from "react"; import { EyeClosedIcon, EyeIcon } from "@primer/octicons-react"; import { useTranslation } from "react-i18next"; - import cn from "classnames"; - import "./text-field.scss"; -export interface TextFieldProps - extends React.DetailedHTMLProps< - React.InputHTMLAttributes, - HTMLInputElement - > { +export interface TextFieldProps extends React.DetailedHTMLProps< + React.InputHTMLAttributes, + HTMLInputElement +> { theme?: "primary" | "dark"; label?: string | React.ReactNode; hint?: string | React.ReactNode; @@ -42,44 +39,27 @@ export const TextField = React.forwardRef( ) => { const id = useId(); const [isFocused, setIsFocused] = useState(false); - const [isPasswordVisible, setIsPasswordVisible] = useState(false); - const { t } = useTranslation("forms"); - const showPasswordToggleButton = props.type === "password"; - - const inputType = useMemo(() => { - if (props.type === "password" && isPasswordVisible) return "text"; - return props.type ?? "text"; - }, [props.type, isPasswordVisible]); - - const hintContent = useMemo(() => { - if (error) - return ( - {error} - ); - - if (hint) return {hint}; - return null; - }, [hint, error]); - + const inputType = props.type === "password" && isPasswordVisible ? "text" : props.type ?? "text"; + const hintContent = error ? ( + {error} + ) : hint ? ( + {hint} + ) : null; const handleFocus: React.FocusEventHandler = (event) => { setIsFocused(true); - if (props.onFocus) props.onFocus(event); + props.onFocus?.(event); }; - const handleBlur: React.FocusEventHandler = (event) => { setIsFocused(false); - if (props.onBlur) props.onBlur(event); + props.onBlur?.(event); }; - const hasError = !!error; - return (
{label && } -
( onBlur={handleBlur} type={inputType} /> - {showPasswordToggleButton && ( )}
- {rightContent}
- {hintContent}
); } ); - -TextField.displayName = "TextField"; +TextField.displayName = "TextField"; \ No newline at end of file