Search code examples
react-nativereact-native-ui-kitten

Checkbox state isn't changing after click


I create an app and use react native and ui kitten. The whole thing works with Expo. Now I have implemented a checkbox, but when I tap on the checkbox with the Expo app (iOS), there is no check. The variable is changed, but the state of the checkbox does not change.

<CheckBox
  style={style.checkbox}
    checked={privacyChecked}
    onChange={(checked) => {
      privacyChecked = checked;
    }}
    >
    I accept the Privacy's
</CheckBox>

The default value is false. I tap on it and I set the variable to true. But the checkbox isn't changing.


Solution

  • You cannot update the state with = assignment

    you need to use setState function like

    onChange={(checked) => this.setState(checked)}
    

    because react will not re-render the component unless it patch the changes and know that it needs to do the re-rendering of component