Virtuoso Message List Scroll to Item
Scroll to Item
Section titled “Scroll to Item”The message list exposes an imperative API to scroll to a specific item. This is useful when you want to scroll to a specific message or a specific index in the list.
import { VirtuosoMessageList, VirtuosoMessageListMethods, VirtuosoMessageListLicense } from '@virtuoso.dev/message-list'
import React from 'react'
export default function App() {
const ref = React.useRef<VirtuosoMessageListMethods>(null)
const offset = React.useRef(100)
return (
<>
<button
onClick={() => {
ref.current.scrollToItem({ index: 50, align: 'center' })
}}
>
Scroll to Item 50 in the center
</button>{' '}
<VirtuosoMessageListLicense licenseKey="">
<VirtuosoMessageList ref={ref} style={{ height: 500 }} data={{ data: Array.from({ length: 100 }, (_, index) => index) }} />
</VirtuosoMessageListLicense>
</>
)
}