preact-scroll-viewport icon indicating copy to clipboard operation
preact-scroll-viewport copied to clipboard

Do keys make sense?

Open kurtextrem opened this issue 7 years ago • 1 comments

Let's say you have unique IDs (such as tweet ids), would it make sense to pass them (regarding performance)? Like so:

<ScrollViewport class="list" rowHeight={this.rowHeight}>
    { rows.map( row => (
	<div class="row" key={row.id}>{row.entry}</div>
      )) }
</ScrollViewport>

kurtextrem avatar Jul 05 '17 07:07 kurtextrem

That will turn off recycling of the rows. In general that will be slower, but it might be desirable if your content really needs to be unmounted+remounted instead of updated in-place. You might find this is true when using homogenous row components that internally render extremely different content for any given row - in that case it can be cheaper to simply recreate each row when displayed, rather than trying to reuse rows from other ID's.

developit avatar Nov 02 '17 04:11 developit