Can't get ref= to work properly
See original GitHub issueHi There! Big fan of the library so far. I’m having an issue getting the ref logic to work for the scrollTo
functionality (trying to mimic ScrollSync functionality from react-virtualized).
Also, please let me know if this is a poor use of issues.
React Version: “16.4.2” React Window: “1.1.2”
The <Grid>
component is calling this.syncHeaderScroll
in the onScroll
prop.
I was hoping syncHeaderScroll would look something like this:
syncHeaderScroll = ({ scrollLeft }) => {
if (this.listRef.current) {
this.listRef.current.scrollTo(scrollLeft)
}
}
I’m trying to make sure I’m not missing anything. When I console.log this.listRef.current
I’m just getting null.
Code snippet here:
export class ActivityStream extends PureComponent {
listRef = React.createRef()
syncHeaderScroll = ({ scrollLeft }) => {
console.log("this.listRef.current", this.listRef.current)
}
render() {
return (
<Fragment>
<List
direction="horizontal"
ref={this.listRef}
height={HEADER_HEIGHT}
itemCount={ACTIVITY_STREAM_HEADERS.length}
itemData={ACTIVITY_STREAM_HEADERS}
itemSize={index => ACTIVITY_STREAM_COLUMN_WIDTHS[index]}
width={tableWidth}
>
{props => <HeaderRenderer filters={filters} onOpenFilter={this.handleOpen} {...props} />}
</List>
<Grid
columnCount={ACTIVITY_STREAM_HEADERS.length}
columnWidth={index => ACTIVITY_STREAM_COLUMN_WIDTHS[index]}
estimatedRowHeight={DEFAULT_ROW_HEIGHT}
height={windowHeight - 250}
itemData={itemData}
overscanCount={10}
rowCount={rowData.length}
rowHeight={index => {
const { first_session_activity, last_session_activity } = rowData[index]
if (first_session_activity && last_session_activity) {
return DEFAULT_ROW_HEIGHT + DIVIDER_BOTTOM_MARGIN + BORDER_WIDTH * 2
}
if (first_session_activity) {
return DEFAULT_ROW_HEIGHT + DIVIDER_BOTTOM_MARGIN + BORDER_WIDTH
}
if (last_session_activity) {
return DEFAULT_ROW_HEIGHT + BORDER_WIDTH
}
return DEFAULT_ROW_HEIGHT
}}
width={tableWidth}
onScroll={this.syncHeaderScroll}
>
{ItemRenderer}
</Grid>
</Fragment>
)
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Why I can't get element by ref using this.$refs in Vue.js 2?
Hi. I have a problem because I need to name the ref as unique because this is a component that will reuse again....
Read more >Understanding refs in Vue - LogRocket Blog
Refs are Vue.js instance properties used to register a reference to HTML elements or child elements in the template of your application.
Read more >Get (a ref) not working on array of components. Quality of life ...
Greetings,. It just doesn't work anymore. Before 4.16 Get always returns a ref. Now if I click 'Change to return a reference' it...
Read more >Refs and the DOM - React
Refs and Function Components ... If you want to allow people to take a ref to your function component, you can use forwardRef...
Read more >Focus management with Vue refs - Learn web development
This should take no inputs. Note that you cannot use an arrow function here since we need access to this to access our...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FWIW I had a similar issue which I resolved by putting
ref.current
in my deps list foruseEffect
rather thanref
.@gautamits That’s what I ended up with back then already as well.