Skip to content

Commit 3b3c713

Browse files
committed
fix mutating state which led to incorrect Formzy work (for didn't reacted on the value update)
1 parent 4bcc613 commit 3b3c713

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

components/Formsy/TiledCheckboxGroup.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ class TiledCheckboxGroup extends Component {
1515

1616
onChange(value) {
1717
const index = this.state.curValue.indexOf(value)
18+
let newValue = [...this.state.curValue]
1819
if (index > -1) {
19-
this.state.curValue.splice(index, 1)
20+
newValue.splice(index, 1)
2021
} else {
21-
this.state.curValue.push(value)
22+
newValue.push(value)
2223
}
23-
this.props.setValue(this.state.curValue)
24-
this.props.onChange(this.props.name, this.state.curValue)
24+
this.setState({ curValue: newValue })
25+
this.props.setValue(newValue)
26+
this.props.onChange(this.props.name, newValue)
2527
}
2628

2729
getCheckMarkIconActive() {

0 commit comments

Comments
 (0)