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: avoid isTruthy call in places where it's not needed #668

Merged
merged 6 commits into from
Mar 6, 2024

Conversation

crnkovic
Copy link
Contributor

@crnkovic crnkovic commented Feb 13, 2024

Summary

https://app.clickup.com/t/86drj8rbd

There are some places in React where we have some value be either some object or null. We can avoid calls to isTruthy in these situations as it's simple enough to check whether some value is null or undefined.

Also, if some component prop is an optional boolean, we can default to false, such as in the TextInput component, to avoid this prop being possibly undefined.

For example:

interface Props {
    isDisabled?: boolean;
}

function SomeComponent({ isDisabled = false }: Props) {
    // isDisabled is now always boolean and doesn't need `isTruthy` call
}

Just uses more TypeScript to make a nicer developer experience.

Checklist

  • I checked my UI changes against the design and there are no notable differences
  • I checked my UI changes for any responsiveness issues
  • I checked my (code) changes for obvious issues, debug statements and commented code
  • I opened a corresponding card on Clickup for any remaining TODOs in my code
  • I added a short description on how to test this PR (if necessary)
  • I added a storybook entry for the component that was added (if necessary)
  • Documentation (if necessary)
  • Tests (if necessary)
  • Ready to be merged

@ItsANameToo ItsANameToo merged commit 209b2ea into develop Mar 6, 2024
12 checks passed
@ItsANameToo ItsANameToo deleted the refactor/is-truthy branch March 6, 2024 14:28
@ItsANameToo ItsANameToo added this to the 0.14.0 milestone Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants