-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation for Collection could be corrected and/or clearer w/r/t recomputeCellSizesAndPositions
#568
Comments
I think refs are explained reasonably clearly in the official React docs. Their use is probably not super common, but they are common enough for things like focus management, animations, 3rd party libraries (like react-virtualized). I'm wary of duplicating the official docs too much here because I won't be able to keep them in sync. componentWillReceiveProps(nextProps) {
if (this._shouldCellsRemeasure(nextProps)) {
// Your data has changed in a way that affects the size or position of cells.
// This is an expensive operation; don't do it unless you need to.
// recomputeCellSizesAndPositions() itself is defined on the Collection component.
this._collection.recomputeCellSizesAndPositions()
} else if (this._shouldCellsRedraw(nextProps)) {
// Your data has changed in a way that requires one or more cells to re-draw.
// Cell sizes and positions are still valid.
// This is a relatively cheap operation.
// forceUpdate() is a built-in method available to all React components.
this._collection.forceUpdate()
}
}
render () {
return (
<Collection
ref={ref => this._collection = ref}
{...this.props}
/>
)
} That being said, it's likely that calling |
Hey @bvaughn, I take your point about refs, but I guess I should have been clearer. It wasn't obvious to me when the docs said that this was a public method that that meant you needed to create a ref in order to be able to apply that method. I use refs all the time and understand how they work, I just hadn't really ever heard the term 'public method' applied to calling a function on a ref. It makes sense now that I think of it. I wonder if others would wonder how to use what you call a public method without seeing a quick example? Perhaps I am just a bit thick :) I'd be happy to work on the other fix when I get some time after this week. Cheers, |
FYI I'm going to pull this into the upcoming version 9 release (PR #577). Long-term I think the solution here is to combine |
Fixed with 00c4def |
I needed a hack/workaround to get my collection to update even though the length of it hadn't changed.
On the home page of the repo it states you can use
forceUpdate
as a public method on the Collection component. I couldn't get this to work. Does it still work or is that part of the documentation out of date?On the docs for the Collection component it states you can force an update by calling
recomputeCellSizesAndPositions
as a public method. That said, it wasn't obvious to me how to do this (as this notion of a public method isn't terribly idiomatic to React Components). After digging for quite a while I learned that you do it like so:And then wherever you need to force a render:
I'll be happy to make this change in a PR as soon as I have a moment if you like.
Cheers!
The text was updated successfully, but these errors were encountered: