Lists Components

Lists and other things that are almost components

Instead of making a separate component for lists I can then generate the results like:

  1. const SearchSuggestions = (props) => {
  2. // renderSearchSuggestion() behaves as a pseudo SearchSuggestion component
  3. // keep it self contained and it should be easy to extract later if needed
  4. const renderSearchSuggestion = listItem => (
  5. <li key={listItem.id}>{listItem.name} {listItem.id}</li>
  6. );
  7. return (
  8. <ul>
  9. {props.listItems.map(renderSearchSuggestion)}
  10. </ul>
  11. );
  12. };

If things get more complex or you want to use this component elsewhere,
you should be able to copy/paste the code out into a new component.
Don’t prematurely componentize.