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

Fix controlled component on Android #137

Merged
merged 1 commit into from
Oct 25, 2021
Merged

Fix controlled component on Android #137

merged 1 commit into from
Oct 25, 2021

Conversation

lyswhut
Copy link
Contributor

@lyswhut lyswhut commented Aug 10, 2021

As a controlled component, we should not change the internal value without authorization, it should always be controlled by the value passed in by JS.

Example code:

export default () => {
  const [check, setCheck] = useState(false)

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <View style={{ flexDirection: 'row', alignItems: 'center' }}>
        <Text>box 1: </Text>
        <CheckBox value={false} />
      </View>

      <View style={{ flexDirection: 'row', alignItems: 'center' }}>
        <Text>box 2: </Text>
        <CheckBox value={check} onValueChange={setCheck} />
      </View>
    </View>
  )
}

Before fix:
GIF2

After:
GIF

@nicholaslee119
Copy link
Collaborator

@lyswhut LGTM! Thanks for your PR, it would be release in next version

@nicholaslee119 nicholaslee119 merged commit 320cc57 into react-native-checkbox:develop Oct 25, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants