Open sujinleeme opened 7 years ago
enter
key, query is not updated. I should know how to handleonKeyPress
andonChange
[object Object]
instead of the contents of the objecttrim()
and when pressing enterKey, it goes to trim string.In onKeyDown you can check key. If it is ENTER pressed call event.preventDefault() to prevent onChange call, or if it is not - do nothing Javascript event queue doesn't contain change event until default handler for keydown event is called. If you call event.preventDefault() in onKeyDown handler no change event will be fired.
JSON.stringify()
is to create a JSON string out of an object/array.
Object object
is the default string representation of a JavaScript Object.
To Fix with : use JSON.stringify(theObject)
theObject.toString()
A quick and dirty way to do this is to stringify your object, and then parse that JSON string back into a brand new object. I recommend creating a utility function, since you’ll likely want to re-use this throughout your app. Below is an example: - Comparing and Modifying Objects in React
function deepCopy(obj) {
if (obj !== undefined && obj !== null) {
return JSON.parse(JSON.stringify(obj));
}
return null;
}
{this.state.books && this.state.books.length > 0
<ol className="books-grid">
{this.state.books && this.state.books.length > 0 ? (
<div>
<BookShelf {...showingBooks} title="Result" />
</div> ) : (
<p>No Books Found :(</p> )}
</ol>
currentMatches() {
const list = this.state.list.SearchKeywords
return list.filter((item) => {
let searchInput = this.props.content;
return item.label.indexOf(searchInput) > -1;
})
}
componentWillReceiveProps
Use LifeCyle methods to update state before render
renderMatches() {
let searchableKeywords = this.state.matched;
return (
<ol
className="match-keywords">
{Object.keys(searchableKeywords).map((k, index) =>
<AutocompleteItem key={k} keywords={this.state.list} {...searchableKeywords[k]} />
)}
</ol>
)
}
componentWillReceiveProps (nextProps){
this.setState({matched : this.currentMatches()})
}
currentMatches() {
const list = this.state.list.SearchKeywords
return list.filter((item) => {
let searchInput = this.props.content;
return item.label.indexOf(searchInput) > -1;
})
}
TODO
AJAX
BooksAPI.get()
to retrieve dataREDUCX
/search
UI
No Book Found
words.Autocomplete Keywords
<li>
<li>