Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the itemIndex to the renderItem function #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

webdeb
Copy link

@webdeb webdeb commented Aug 31, 2017

This passes the itemIndex to the renderItem function, in cases where you need to know which index the item has, it might be helpful:

For example:

  • styling the first / last item
  • grouping by index and offset.
  • Numeration of the items inner the render function.. First. 2. 3.. Last:

(Yes, you can solve some of this by preparing the suggestions before you are passing them to the component (in case of React-Autosuggest), but this requires an additional loop before the rendering.

@webdeb
Copy link
Author

webdeb commented Aug 31, 2017

  • Tests updated...

@marvinhagemeister
Copy link

Awesome, I just ran into the same issue where I'd need the index of the current suggestion for an API-call.

@webdeb
Copy link
Author

webdeb commented Aug 31, 2017

Maybe it's TOO MUCH :), but I am seriously thinking about an additional ItemsLength prop, which would be given to each renderItem.

The benefits are, that you don't have to use this.state.items.length in your parent component to know if this is the last or not.. Additionally this.state.items.length is maybe not the real source of truth because in your render, there could be a filter already suggestions={this.state.items.filter()} for example, so ItemList in this package is a better candidate to provide us this value?

@marvinhagemeister
Copy link

@webdeb I like the thought, but I'd prefer to simply pass the whole suggestion array to the developer instead of passing just the length value. That way devs are not restricted to specific parts of an object.

@webdeb
Copy link
Author

webdeb commented Aug 31, 2017

@marvinhagemeister oh yeah, even better 👍 🚀
@moroshko What do you think? I'd like to put it in that PR..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants