MCPcopy Create free account
hub / github.com/bvaughn/react-virtualized / Example

Function Example

src/routes/table/examples/TableImperativeMethods.tsx:22–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20import { AutoSizer } from "react-virtualized-auto-sizer";
21
22function Example() {
23 const tableRef = useRef<TableImperativeAPI>(null);
24
25 const [align, setAlign] = useState<Alignment>("center");
26 const [index, setIndex] = useState("500");
27
28 const onSubmit = (event: FormEvent) => {
29 event.preventDefault();
30
31 tableRef.current?.scrollToRow({ align, index: parseInt(index, 10) });
32 };
33
34 const scrollToTop = () => {
35 tableRef.current?.scrollToPosition({ scrollTop: 0 });
36 };
37
38 return (
39 <div className="flex flex-col gap-2">
40 <form className="flex flex-wrap items-end gap-2" onSubmit={onSubmit}>
41 <label className={LABEL_CLASS_NAME}>
42 Row
43 <input
44 className={INPUT_CLASS_NAME}
45 max={list.length - 1}
46 min={0}
47 onChange={(event) => setIndex(event.target.value)}
48 required
49 type="number"
50 value={index}
51 />
52 </label>
53 <label className={LABEL_CLASS_NAME}>
54 Alignment
55 <select
56 className={INPUT_CLASS_NAME}
57 onChange={(event) => setAlign(event.target.value as Alignment)}
58 value={align}
59 >
60 <option value="auto">auto</option>
61 <option value="start">start</option>
62 <option value="center">center</option>
63 <option value="end">end</option>
64 </select>
65 </label>
66 <button className={BUTTON_CLASS_NAME} type="submit">
67 Scroll
68 </button>
69 <button
70 className={BUTTON_CLASS_NAME}
71 onClick={scrollToTop}
72 type="button"
73 >
74 Scroll to top
75 </button>
76 </form>
77 <AutoSizer
78 renderProp={({ width }) =>
79 width !== undefined ? (

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected