Created
March 28, 2020 05:41
-
-
Save CalledByThe4ire/5942873f1720a469b6fff24bb1d28bb5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| this.state = { | |
| productsFilter: { | |
| fields: { | |
| min: { | |
| price: minBy(product => product.price, productsList).price, | |
| isValid: true | |
| }, | |
| max: { | |
| price: maxBy(product => product.price, productsList).price, | |
| isValid: true | |
| } | |
| }, | |
| isValid: true | |
| }, | |
| productsList | |
| }; | |
| updateProductsFilterFieldValidty = (name, data) => { | |
| this.setState(prevState => ({ | |
| productsFilter: { | |
| fields: { | |
| ...prevState.productsFilter.fields, | |
| [name]: { ...prevState.productsFilter.fields[name], ...data } | |
| }, | |
| isValid: prevState.productsFilter.isValid | |
| } | |
| })); | |
| }; | |
| updateProductsFilterFieldPrice = fields => { | |
| fields.forEach(field => { | |
| const name = Object.keys(field); | |
| this.setState(prevState => ({ | |
| productsFilter: { | |
| fields: { | |
| ...prevState.productsFilter.fields, | |
| [name]: { | |
| ...prevState.productsFilter.fields[name], | |
| ...field[name] | |
| } | |
| }, | |
| isValid: prevState.productsFilter.isValid | |
| } | |
| })); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment