Skip to content

Commit 8acf054

Browse files
Add 'componentDidUpdate' lifecicle event.
1 parent bb2ba04 commit 8acf054

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

package-lock.json

Lines changed: 40 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap-switch-button-react.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export default class BootstrapSwitchButton extends React.Component {
5050
};
5151
}
5252

53+
componentDidUpdate(_, prevState) {
54+
const { checked } = this.props
55+
if(typeof checked === "boolean" && checked !== prevState.checked) {
56+
this.setState({ checked })
57+
}
58+
}
59+
5360
toggle = event => {
5461
this.state.checked ? this.off() : this.on();
5562
};

0 commit comments

Comments
 (0)