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.

Child Components Never Re-rendered using AutoSizer

See original GitHub issue

I’m using the AutoSizer with the List as a child of it.

The problem I’m having is that the child virtual list is never re-rendered with new properties - I assume because the AutoSizer is declared “Pure” and as I don’t pass any properties to it directly it will never re-render as it doesn’t detect a change.

As shown below I have my main component called ComponentA whose render function contains an AutoSizer with a single child “List”.

The property “rowCount” on the List is driven by a property on ComponentA so we want the number of rows to change based on what is passed to ComponentA via props

class ComponentA {
	
	render() {
		<AutoSizer>
			{this.renderSizedList}
		</AutoSizer>	
	}

	private renderSizedList = (dims: Dimensions) => {
        const { width, height } = dims;

        return (
            <List
                width={width}
                height={height}
                rowHeight={64}
                rowCount={this.props.postFilteredRecordCount}
                rowRenderer=...
            />
        );
    }	
}

At the moment the only way I can get around this is to grab a reference to the AutoSizer when it mounts and then inside the React life-cycle event “componentWillReceiveProps” call “forceUpdate()” on it then it’s ok. But this doesn’t feel right.

So should the AutoSizer really be declared as Pure or is there some other way it should be used? The documentation is a little confusing in terms of it talking about how to use children via a “ChildComponent” property which I can’t see. I also can’t find any examples that do anything different from what I have above (where the “List” is specifically a child of the AutoSizer)

I have included a plunker example which is similar although it uses your template example with two lists. In the first list clicking the button increases the row height but in the second list which has an AutoSizer around it it doesn’t. The button handler included a commented out line which can be uncommented to highlight the workaround I’m having to use to get it working.

https://plnkr.co/edit/Pk7dH7?p=preview

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bvaughncommented, Jul 3, 2017

The documentation is a little confusing in terms of it talking about how to use children via a “ChildComponent” property which I can’t see.

The docs don’t mention ChildComponent to my knowledge, other than a CHANGELOG entry for when that property was removed back in version 4.0.

Did you try what is mentioned in this section: https://github.com/bvaughn/react-virtualized#pure-components

Pass-thru props

The shallowCompare method will detect changes to any props, even if they aren’t declared as propTypes. This means you can also pass through additional properties that affect cell rendering to ensure changes are detected.

In your case, this could mean:

<AutoSizer rowCount={this.props.postFilteredRecordCount}>
  {this.renderSizedList}
</AutoSizer>	
0reactions
nata7checommented, Nov 22, 2022

Is there any news concerning this issue? This is also something we came across (2022). Any help in solving this is highly appreciated 🙏🏻

Read more comments on GitHub >

github_iconTop Results From Across the Web

When using React-Virtualized AutoSizer, children not being ...
I have a component which uses react-virtualized AutoSizer, and inside this component there is a react-virtualized List.
Read more >
react-virutalized AutoSizer rerender issue : r/reactjs - Reddit
I am creating a virtualized list component using react ... the only way to make it rerender will be to make the children...
Read more >
When does React re-render components? - Felix Gerschau
Force a React component to rerender. In the two years that I've been working with React professionally, I've never come to a point...
Read more >
Avoiding React component re-renders with React.memo
A component can re-render even if its props don't change. More often than not this is due to a parent component re-rendering causing...
Read more >
5 Ways to Avoid React Component Re-Renderings
How to Avoid Unnecessary Re-rendering in React. React components have evolved a long way from their inception. Still, many developers find ...
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