**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.
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)
}
`````
The state
isPressed
is initialized with a complex expression that can be simplified. SinceuseState
already handles undefined values gracefully, you can directly passpressed || 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_