ReactJS by Example - Building Modern Web Applications with React by 2016

ReactJS by Example - Building Modern Web Applications with React by 2016

Author:2016
Language: eng
Format: mobi, epub
Publisher: Packt Publishing


"Shawn, this is functional; however, it's not following the React way. React assumes that the state object is immutable. Here we are using reference to the books from the existing state when we are assigning value to unsortedBooks."

let unsortedBooks = this.state.books;

"Later, we are mutating unsortedBooks into sortedBooks; however, as a side-effect, we are also mutating the current value of this.state."

_sortByTitle() { let sortByAttribute = this.state.sorting === 'asc' ? "title" : "-title"; let unsortedBooks = this.state.books; console.log("Before sorting :"); console.log(this.state.books[0].title); let sortedBooks = unsortedBooks.sort(sortBy(sortByAttribute)); console.log("After sorting :"); console.log(this.state.books[0].title); // this.setState({ books: sortedBooks, sorting: this._toggleSorting() }); },



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.