Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

Commit 403bd89

Browse files
author
Sanjana Desai
committed
bug fix in setState of componentWillMount - handling situation in which there are more than one product options
1 parent 8f249f4 commit 403bd89

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

‎react-apollo/src/components/Product.js‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ class Product extends Component {
55
constructor(props) {
66
super(props);
77

8-
this.state = {};
8+
this.state = {
9+
selectedOptions: {}
10+
};
911

1012
this.handleOptionChange = this.handleOptionChange.bind(this);
1113
this.handleQuantityChange = this.handleQuantityChange.bind(this);
@@ -14,9 +16,12 @@ class Product extends Component {
1416

1517
componentWillMount() {
1618
this.props.product.options.forEach((selector) => {
17-
this.setState({
18-
selectedOptions: { [selector.name]: selector.values[0] }
19-
});
19+
this.setState((prevState) => ({
20+
selectedOptions:{
21+
...prevState.selectedOptions,
22+
[selector.name]: selector.values[0]
23+
}
24+
}));
2025
});
2126
}
2227

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /