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

Create enabledAndNotLoading state and don't set enabled in parameter #13890

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sagar0-0
Copy link
Contributor

@Sagar0-0 Sagar0-0 commented Jan 8, 2025

First time contributor checklist

Contributor checklist

  • Device Realme GT NET 3T, Android 14
  • Device Infinix Hot 20 Pro, Android 14
  • Virtual device Pixel 8 Pro, Android 14
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Description

An important thing to note here is,
NEVER set a param default value to another parameter(If they are interdependent).
This can lead to unexpected behavior from the call site.

For example in this case:
If the TabRow is also dependent on any other condition to enable the Toggle, and it is set to true at the call site. Then the default value of enabled = !isLoading will be overridden to always true, which leads to inconsistent enabled state behavior for all elements.

So, a better way is to keep the default values in params as it is, and then abstract out the logic for handling the "interdependent" states as I did here with enabledAndNotLoading. And now the component's developer is assured to have the states consistent.

Let's make sure other places are also following the same pattern.

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

Successfully merging this pull request may close these issues.

1 participant