Skip to content

frontend: Refactor state initialization to lazy state initializers in NumRowsInput #5897

@YadavAkhileshh

Description

@YadavAkhileshh

Description

In frontend/src/components/App/Settings/NumRowsInput.tsx, there are redundant useMemo hooks used solely to calculate the initial values of selectedValue and customValue state variables.

These useMemo hooks use variables like options but pass an empty dependency array [] (forcing calculation only on mount). This violates the ESLint rule for hooks, requiring the use of // eslint-disable-next-line react-hooks/exhaustive-deps hacks.

Proposed Improvement

Using useMemo to initialize state is a React anti-pattern. Instead, we can use React's standard Lazy State Initializer pattern. By passing a initialization function directly inside useState(() => { ... }), we can:

  1. Ensure the computation runs exactly once on mount.
  2. Completely remove the redundant useMemo hooks.
  3. Clean up the codebase by removing the eslint-disable workarounds.

Expected Behavior

The settings UI works exactly as before, but with cleaner code, better performance, and standard-compliant React hooks usage.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions