crazycodeboy / react-native-check-box

Checkbox component for react native, it works on iOS and Android.
MIT License
518 stars 184 forks source link

Make checkbox stateless #10

Closed gurch101 closed 7 years ago

gurch101 commented 7 years ago

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 the onClick callback.

rgoldiez commented 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.

ianhowe76 commented 7 years ago

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

grahammcculloch commented 7 years ago

@crazycodeboy any chance of creating a release that includes the commit from this PR?