我正在使用react-window尝试生成一个列表。
使用他们使用的缺省行,他们创建
const Row = ({ index, style }) => (
<div className={index % 2 ? 'ListItemOdd' : 'ListItemEven'} style={style}>
Row {index}
</div>
);然后,他们使用默认元素创建列表,如下所示
<List
className="List"
height={150}
itemCount={1000}
itemSize={35}
width={300}
>
{Row}
</List>返回的也是一个对象,其形式与我的相同

我正在尝试做大致相同的事情。
我正在使用List组件
<List
className="List"
height={150}
itemCount={20}
itemSize={35}
width={300}>
{renderUsers(users)}
</List>renderUsers(users)输出const renderUsers = map((user) => <User user={user} key={user.__id} />);的位置
我收到一个错误,说
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `List`.返回的是一个对象(问题是什么?)看起来像这样

我该如何解决这个问题?
发布于 2021-01-19 23:44:36
您需要将组件作为List的子级传递,而不是元素列表。
const Row = ({ data, index, style }) => {
const user = data.users[index];
return (
<div style={style}>
<User user={user} key={user.__id} />
</div>
)
};和
<List
className="List"
height={150}
itemCount={users.length}
itemSize={35}
itemData={{
users,
}}
width={300}>
{Row}
</List>https://stackoverflow.com/questions/65794658
复制相似问题