question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to pass a render function for an item

See original GitHub issue

react-virtualized takes a rowRenderer prop, and FlatList in react native takes a similar renderItem prop. What is the reason you chose to go with an API where you pass a component as a child instead?

Doing so forces you to go through this memoization process if you want to pass props down to the item. I would think this is an extremely common use case, and if you accept a render function instead we can pass down any props we want as normal props, allowing the user to leverage any of React’s builtin checks for sCU (PureComponent, React.memo).

Would you be open to expanding the API a bit? Instead of passing a component as a child, we could instead provide two different props: itemComponent and renderItem, the former just passed a component (like now) and the latter passes the data into a function which returns a component.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:31 (14 by maintainers)

github_iconTop GitHub Comments

4reactions
jlongstercommented, Nov 6, 2018

Thanks for taking the time to respond so thoroughly!

2reactions
bvaughncommented, Nov 7, 2018

In the past 24 hours, I’ve chatted with Spencer about React Native’s FlatList, Necolas about Twitter’s virtualization, and you here– and I’m getting my threads mixed up a bit at this point, but…

If you come up with a concrete suggested change to react-window (or even if you have one now) pitch it here as a comment, let me sit and think on it a bit, and see if we can’t come up with a compromise that would address your concerns.

I’m not actually using my windowing components very much these days, so it’s easy for me to get hung up on theoretical usage that’s out of touch. I appreciate the feedback from people who have used them a lot.

I think your original suggestion has been to provide a plain function render option rather than a component. If that’s still your primary suggestion, then what would your proposed API be like given that I definitely want to continue treating item renderers as React elements by default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Reference Guide: Render props - LogRocket Blog
An all-in-one reference guide on render props in React, including how to implement render props, how to implement HOCs, and more.
Read more >
How to create a render prop component | by Sean McPherson
Instead of passing a string or object, you pass a function as a prop. <Name renderProp={() => "Passing a function as a prop!"}...
Read more >
Passing Functions to Components - React
Using Function.prototype.bind in render creates a new function each time the component renders, which may have performance implications (see below).
Read more >
How to pass data to a React component's props.children
You can pass a render function to your component in place of its children. You can merge new props into the elements passed...
Read more >
Render Props Pattern
To the Component element, we have to pass a prop called render , which is a function that returns a React element. See...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found