rad-ui / ui

Rad UI is an open-source, headless UI component library for building modern, fast, performant, accessible React applications
http://rad-ui.com
MIT License
9 stars 11 forks source link

Consider simplifying the state initialization. #347

Closed kotAPI closed 6 days ago

kotAPI commented 6 days ago
          **Consider simplifying the state initialization.**

The state isPressed is initialized with a complex expression that can be simplified. Since useState already handles undefined values gracefully, you can directly pass pressed || defaultPressed.

-  const [isPressed = false, setIsPressed] = useState(pressed || defaultPressed)
+  const [isPressed, setIsPressed] = useState(pressed || defaultPressed)
Committable suggestion > :bangbang: **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion const [isPressed, setIsPressed] = useState(pressed || defaultPressed) const handlePressed = () => { const updatedPressed = !isPressed setIsPressed(updatedPressed) onChange(updatedPressed) } `````

_Originally posted by @coderabbitai[bot] in https://github.com/rad-ui/ui/pull/343#discussion_r1654611302_