Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove && and use ternary #58

Open
wit03 opened this issue Oct 9, 2024 · 0 comments
Open

refactor: remove && and use ternary #58

wit03 opened this issue Oct 9, 2024 · 0 comments

Comments

@wit03
Copy link
Member

wit03 commented Oct 9, 2024

          _:warning: Potential issue_

Prevent 'false' from appearing in className

When state.drawer is false, the expression ${state.drawer && 'bg-gray-50'} can result in the string 'false' being included in the className, which may cause unintended styling issues. To avoid this, use a ternary operator or a conditional class name utility to handle conditional classes correctly.

Apply this diff to fix the issue:

- className={`flex lg:hidden h-10 items-center gap-2 border  rounded-full px-3 py-2 cursor-pointer hover:bg-gray-100 ${
-   state.drawer && 'bg-gray-50'
- }`}
+ className={`flex lg:hidden h-10 items-center gap-2 border rounded-full px-3 py-2 cursor-pointer hover:bg-gray-100 ${
+   state.drawer ? 'bg-gray-50' : ''
+ }`}

Or, consider using the classnames library:

+ import classNames from 'classnames'
...
- className={`flex lg:hidden h-10 items-center gap-2 border  rounded-full px-3 py-2 cursor-pointer hover:bg-gray-100 ${
-   state.drawer && 'bg-gray-50'
- }`}
+ className={classNames(
+   'flex lg:hidden h-10 items-center gap-2 border rounded-full px-3 py-2 cursor-pointer hover:bg-gray-100',
+   { 'bg-gray-50': state.drawer }
+ )}
📝 Committable suggestion

‼️ 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.

              className={`flex lg:hidden h-10 items-center gap-2 border rounded-full px-3 py-2 cursor-pointer hover:bg-gray-100 ${
                state.drawer ? 'bg-gray-50' : ''
              }`}
            >

Originally posted by @coderabbitai[bot] in #46 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant