From 6b034100bd3aae1015cb0bd1f479aea5106c597b Mon Sep 17 00:00:00 2001 From: PinkiPalacios Date: Tue, 3 Apr 2018 19:20:03 -0300 Subject: [PATCH 1/2] makes posible to check/uncheck from parent component by changing isChecked prop --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index 07d09f1..b39da0b 100755 --- a/index.js +++ b/index.js @@ -103,6 +103,14 @@ export default class CheckBox extends Component { ); } + componentWillReceiveProps( newProps ){ + if (this.props.isChecked != this.state.isChecked){ + this.setState({ + isChecked: !this.state.isChecked + }) + } + } + render() { return ( Date: Tue, 3 Apr 2018 19:45:00 -0300 Subject: [PATCH 2/2] Fixes bug --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b39da0b..651a7aa 100755 --- a/index.js +++ b/index.js @@ -104,7 +104,7 @@ export default class CheckBox extends Component { } componentWillReceiveProps( newProps ){ - if (this.props.isChecked != this.state.isChecked){ + if (newProps.isChecked != this.state.isChecked){ this.setState({ isChecked: !this.state.isChecked })