without all relevent the code, I can only guess. Try something like this:
struct SecondView: View {
@ObservedObject var viewModel: MyViewModel
// ...
var body: some View {
// ...
ForEach ($viewModel.itemsArray, id: \.self) { $item in // <-- here
HStack {
Button(action: {
if item.quantity < 2 { // <-- here
item.quantity = 1
} else {
item.quantity -= 1
}
}) {
Image(systemName: "minus.circle").foregroundColor(Color.gray)
}
Text("\(item.quantity)")
Button(action: { item.quantity += 1 }) { // <-- here
Image(systemName: "plus.circle").foregroundColor(Color.black)
}
}
}
}
}
Anytime we create a timeout we should s clear it on componentWillUnmount, if it hasn't fired yet.
let myVar;
const Component = React.createClass({
getInitialState: function () {
return {position: 0};
},
componentDidMount: function () {
myVar = setTimeout(()=> this.setState({position: 1}), 3000)
},
componentWillUnmount: () => {
clearTimeout(myVar);
};
render: function () {
return (
<div className="component">
{this.state.position}
</div>
);
}
});
ReactDOM.render(
<Component />,
document.getElementById('main')
);