fix: use lazy initializer for useState with function calls

Calling getTerminalKey() and getDefaultDateRange() directly in useState
re-runs them on every render. Wrap in an arrow function so they execute
only once during component initialization.
This commit is contained in:
Yandi
2026-02-22 20:34:38 +07:00
parent 5435e1dac4
commit 43f9f545c6
2 changed files with 4 additions and 2 deletions
@@ -63,7 +63,7 @@ export const ShowRequests = () => {
const [dateRange, setDateRange] = useState<{ const [dateRange, setDateRange] = useState<{
from: Date | undefined; from: Date | undefined;
to: Date | undefined; to: Date | undefined;
}>(getDefaultDateRange()); }>(() => getDefaultDateRange());
// Check if logs exist to determine if traefik has been reloaded // Check if logs exist to determine if traefik has been reloaded
// Only fetch when active to minimize network calls // Only fetch when active to minimize network calls
@@ -32,7 +32,9 @@ export const TerminalModal = ({
serverId, serverId,
asButton = false, asButton = false,
}: Props) => { }: Props) => {
const [terminalKey, setTerminalKey] = useState<string>(getTerminalKey()); const [terminalKey, setTerminalKey] = useState<string>(() =>
getTerminalKey(),
);
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const isLocalServer = serverId === "local"; const isLocalServer = serverId === "local";