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.

A way to get rendered indexes.

See original GitHub issue

Problem:

I am changing some values of rendered items in List component. But the list isn’t showing my change. I am making a workaround using forceUpdateGrid. But I should detect in my props if any of my items was changed.

Other solution.

Detect if any value of items in current RENDERED RANGE changed, and re-render them.

Workaround

I am using a List component and I saved as virtualList ref.

  componentWillReceiveProps(nextProps) {
    const startIndex = this.virtualList.Grid._rowStartIndex;
    const stopIndex = this.virtualList.Grid._rowStopIndex;
    this.shouldForceList = compareItems(startIndex, stopIndex, this.pros, nextProps); // comparte item list.
  }

  componentDidUpdate() {
    if (this.shouldForceList && this.virtualList) {
      this.virtualList.forceUpdateGrid();
    }
  }

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
bvaughncommented, Feb 16, 2017

I am changing some values of rendered items in List component. But the list isn’t showing my change.

The reason for this is explained briefly here. forceUpdateGrid is an acceptable solution for this. A unique property that changes when your items changes (such as an incremented counter) would also work.

Detect if any value of items in current RENDERED RANGE changed, and re-render them.

If item changes invalidate their size then you should always inform List (by calling recomputeRowHeights , which will also re-render for you). If it only affects their visuals, not size, then calling forceUpdateGrid is sufficient.

Detect if any value of items in current RENDERED RANGE changed, and re-render them.

You can do this with the onRowsRendered property mentioned in the docs. It will trigger each time the visual range of rows change.

So try something like this:

  _onRowsRendered({ startIndex, stopIndex }) {
    this._startIndex = startIndex
    this._stopIndex = stopIndex
  }

  componentWillReceiveProps(nextProps) {
    // Note that this may be expensive depending on how often this method fires.
    // It may be cheaper to calculate this wherever your items are changing.
    const hasChanged = compareItems(
      this._startIndex,
      this._stopIndex,
      this.pros,
      nextProps
    );

    if (hasChanged) {
      // This property will trigger a re-render of List since it's changed.
      this._listChangeCounter++
    }
  }

  render() {
    return (
      <List
        listChangeCounter={this._listChangeCounter}
        onRowsRendered={this._onRowsRendered}
        {...this.props}
      />
    )
  }

I am going to close this issue because I believe you have all of the tools you need to do what you’re looking for. 😄

1reaction
bvaughncommented, Apr 6, 2017

Yup. RV doesn’t know anything about the second case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Your Pages Crawled, Rendered, And Indexed - Botify
We're going to explore why focusing on crawling, rendering, and indexing is a crucial first step in any enterprise's SEO methodology. How are ......
Read more >
How to retrieve of index of for-loop rendered React Components
But I realized I have no idea how to pass i from index to onClick. How can I do this? Am I approaching...
Read more >
Rendering from Vertex and Index Buffers (Direct3D 9)
An index buffer 'indexes' into the vertex buffer so each unique vertex needs to be stored only once in the vertex buffer. The...
Read more >
How (& Why) Search Engines Render Pages
So, the short answer as to when rendering takes place is: “after indexing” and the timeline is variable but short, essentially meaning that...
Read more >
JavaScript rendering and indexing: Cautionary tales and how ...
While it isn't a good idea to rely on only one test like this, their experience matches up with my own. I have...
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