Closed gurch101 closed 7 years ago
Alternatively, have the onClick call back return the new state of the component. The current implementation has it's own state but requires the parent component to find state of the checkbox to know how to update state at a higher level.
I have created an alternative option to to allow component to be used in current uncontrolled mode
https://github.com/crazycodeboy/react-native-check-box/pull/12
@crazycodeboy any chance of creating a release that includes the commit from this PR?
using props to set the initial state of the checkbox results in the duplication of the "true state" of the checkbox in both this code and the caller that handles the
onClick
callback. Make this component stateless so that the caller is the main "keeper of the state".Example where the current code would fail: Have a screen with a "Reset Checkbox" button. Clicking this button would do nothing since the props change is not handled. One solution would be to add
componentWillReceiveProps
but I'd imagine the caller would almost always maintain the checkbox state itself through theonClick
callback.