admin管理员组文章数量:1401849
I'm using 'react-virtualized' to render an infinite scrolling list.
However, I am having trouble rendering the rowHeight
dynamically. I made an attempt, but it only is relevent for desktop, and feels wrong.
I tried following the examples, but had no success.
What is the correct way to calculate the true row height?
It should be responsive to mobile.
Here is an example:
class App extends React.Component {
render() {
return (
<div>
<AutoSizer>
{({ height, width }) => (
<List
height={600}
width={width}
rowCount={foo.length}
rowHeight={({ index }) => {
const x = foo[index];
if (x.name.length < 10) { return 20; }
else if (x.name.length > 9) { return 40;}
}}
rowRenderer={({ index, style }) => {
const x = foo[index];
return (
<div key={index} style={style}>
{x.name}
</div>
);
}}
/>
)}
</AutoSizer>
</div>
);
}
}
I'm using 'react-virtualized' to render an infinite scrolling list.
However, I am having trouble rendering the rowHeight
dynamically. I made an attempt, but it only is relevent for desktop, and feels wrong.
I tried following the examples, but had no success.
What is the correct way to calculate the true row height?
It should be responsive to mobile.
Here is an example:
https://codesandbox.io/s/ADARgvlxB
class App extends React.Component {
render() {
return (
<div>
<AutoSizer>
{({ height, width }) => (
<List
height={600}
width={width}
rowCount={foo.length}
rowHeight={({ index }) => {
const x = foo[index];
if (x.name.length < 10) { return 20; }
else if (x.name.length > 9) { return 40;}
}}
rowRenderer={({ index, style }) => {
const x = foo[index];
return (
<div key={index} style={style}>
{x.name}
</div>
);
}}
/>
)}
</AutoSizer>
</div>
);
}
}
Share
Improve this question
asked Jul 27, 2017 at 13:36
YconYcon
1,9506 gold badges32 silver badges56 bronze badges
1 Answer
Reset to default 4What is the correct way to calculate the true row height?
This is what the react-virtualized CellMeasurer
ponent is for. You can see a demo of it measuring dynamic heights here. The source code for the demo are the *.example.js
files here.
本文标签: javascriptDynamic height with infinite scroll (reactvirtualized)Stack Overflow
版权声明:本文标题:javascript - Dynamic height with infinite scroll (react-virtualized) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744324026a2600641.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论