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.

I do not understand how to pass data to the list

See original GitHub issue

I read the docs and saw the examples. All of them seem to pass to the list a component rather than a JSX. So how do I pass data to the rows? I tried adding a data tag to the List but to no avail.



import React, { useRef, useEffect } from "react";
import { VariableSizeList as List } from "react-window";

// These row heights are arbitrary.
// Yours should be based on the content of the row.
const rowHeights = new Array(1000)
    .fill(true)
    .map(() => 25 + Math.round(Math.random() * 50));

const getItemSize = index => rowHeights[index];

function Row(props) {
    console.log("props -> ", props);
    const { index, style } = props;
    return <div style={style}>Row {index}</div>;
}

const data = [
    { id: 1, name: "james" },
    { id: 2, name: "james" },
    { id: 3, name: "james" },
    { id: 4, name: "james" },
    { id: 5, name: "james" },
];
function VirtualList(props) {
    const listRef = useRef();

    useEffect(() => {
        listRef.current.scrollToItem(200, "start");
    }, []);

    return (
        <List
            ref={listRef}
            height={150}
            data={data}
            itemCount={1000}
            itemSize={getItemSize}
            width={300}
        >
            {Row}
        </List>
    );
}

export default VirtualList;

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bvaughncommented, Nov 5, 2019

Use the itemData prop

https://react-window.now.sh/#/examples/list/memoized-list-items

On Tue, Nov 5, 2019 at 4:18 AM guywek notifications@github.com wrote:

I read the docs and saw the examples. All of them seem to pass to the list a component rather than a JSX. So how do I pass data to the rows? I tried adding a data tag to the List but to no avail.

import React, { useRef, useEffect } from “react”;import { VariableSizeList as List } from “react-window”; // These row heights are arbitrary.// Yours should be based on the content of the row.const rowHeights = new Array(1000) .fill(true) .map(() => 25 + Math.round(Math.random() * 50)); const getItemSize = index => rowHeights[index]; function Row(props) { console.log("props -> ", props); const { index, style } = props; return <div style={style}>Row {index}</div>; } const data = [ { id: 1, name: “james” }, { id: 2, name: “james” }, { id: 3, name: “james” }, { id: 4, name: “james” }, { id: 5, name: “james” }, ];function VirtualList(props) { const listRef = useRef();

useEffect(() => {
    listRef.current.scrollToItem(200, "start");
}, []);

return (
    <List
        ref={listRef}
        height={150}
        data={data}
        itemCount={1000}
        itemSize={getItemSize}
        width={300}
    >
        {Row}
    </List>
);

} export default VirtualList;

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bvaughn/react-window/issues/373?email_source=notifications&email_token=AAAHHHMSYH2TZJABGG6HSY3QSFQCVA5CNFSM4JJB24X2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HW4CC7Q, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAHHHKAR3NZFLIKN3IOQE3QSFQCVANCNFSM4JJB24XQ .

0reactions
suryakumaracommented, Feb 9, 2022

the docs still confusing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How to pass data to list? - Stack Overflow
First add class Client in separated .cs file. public class Client { public string Telefon { get; set; } public string Navn {...
Read more >
Function arguments - Manual - PHP
Information may be passed to functions via the argument list, which is a comma-delimited list of expressions. The arguments are evaluated from left...
Read more >
Pass-by-value, reference, and assignment | Pydon't - Mathspp
This article explains why Python doesn't use a pass-by-value system, nor a pass-by-reference.
Read more >
More on data validation - Microsoft Support
You can use data validation to restrict the type of data or values that users enter into cells. This is an advanced topic...
Read more >
Defining Your Own Python Function
You'll also learn about passing data to your function, and returning data ... the sentinel value indicates no argument is given, create a...
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