bvaughn / bvaughn/react-window
Scrolling to a dynamic height row?
- Dominant language
- TypeScript
- Stars
- 17.2k
- Forks
- 816
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 1
Description
I tried using [imperative methods](https://react-window.vercel.app/list/imperative-methods) according to the docs, but it won't scroll to row.
Any updated example?
(below is what I tried)
page.tsx
```tsx
```
Example.tsx
```tsx
"use client";
import { List, useDynamicRowHeight, useListRef } from "react-window";
import { RowComponent } from "./RowComponent";
export function Example({ names }: { names: string[] }) {
const rowHeight = useDynamicRowHeight({
defaultRowHeight: 25,
});
const listRef = useListRef(null)
const onClick = () => {
const list = listRef.current;
console.log("scrolling to row 250", list);
list?.scrollToRow({
align: "auto", // optional
behavior: "auto", // optional
index: 250
});
console.log("scrolled to row 250", list);
};
return (
<>
Go to row 250
);
}
```
RowComponent.tsx
```tsx
import { type RowComponentProps } from "react-window";
export function RowComponent({
index,
names,
style
}: RowComponentProps<{
names: string[];
}>) {
return (
{names[index]}
);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.