Skip to content

Instantly share code, notes, and snippets.

@ahandsel
Created November 19, 2021 02:35
Show Gist options
  • Select an option

  • Save ahandsel/755fcb2a66ee0351ff608e6b413df439 to your computer and use it in GitHub Desktop.

Select an option

Save ahandsel/755fcb2a66ee0351ff608e6b413df439 to your computer and use it in GitHub Desktop.

Coding from workshop branch to master

src/index.js

  • Inside the handleChange filter the results by taking in listItems & looking for e.target.value.toLowerCase()
  • Then set setSearchResults(filterResults)
const handleChange = e => {
  let filterResults = listItems.filter(dataRecord => dataRecord.title.toLowerCase().includes(e.target.value.toLowerCase()));
  console.log('filterResults');
  console.log(filterResults);
  setSearchResults(filterResults);
};

src/components/SearchBar.js

  • Filling in the <input /> element to build the search bar
  • onChange={props.handleChange}
  • className='SearchBar'
<input
  className='SearchBar'
  type='text'
  id='header-search'
  placeholder='Search Manga Titles'
  name='Search Bar for Manga Titles'
  onChange={props.handleChange}
/>

src/components/ResultList.js

  • Finishing the ResultList component to output the list of records by using map function on searchResults
  • {props.searchResults.map(function (resultRecord) {})}
  • Inside we would return JSX: return <li key={resultRecord.uniqueKey}><b className='TitleBold'>{resultRecord.title}</b> written by {resultRecord.author}</li>
<ul>
  {props.searchResults.map(function (resultRecord) {
    return <li key={resultRecord.uniqueKey}><b className='TitleBold'>{resultRecord.title}</b> written by {resultRecord.author}</li>
  })}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment