SDKsReact Native
Load older messages
Load historical messages backward in time with pagination using the OpenIM React Native SDK.
Page backward in time to retrieve earlier historical messages in a conversation:
Pass an empty string "" for startClientMsgID when fetching the initial page. On subsequent upward scrolls, supply the clientMsgID of the earliest loaded message in the current list.
const page = await OpenIMSDK.getAdvancedHistoryMessageList({
conversationID,
startClientMsgID: oldestMessage?.clientMsgID ?? '',
count: 30,
viewType: ViewType.History,
});Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | string | Yes | Target conversation ID. |
startClientMsgID | string | Yes | Anchor client message ID; pass an empty string "" for the initial page. |
count | number | Yes | Maximum number of messages to fetch in this batch. |
viewType | ViewType | Yes | Retrieval context; pass ViewType.History when browsing standard chat logs. |
Return value
A resolved Promise returns an AdvancedGetMessageResult object:
| Field | Type | Description |
|---|---|---|
messageList | MessageItem[] | Array of historical messages for the current page, sorted chronologically. |
isEnd | boolean | Indicates whether pagination has reached the earliest message; true means no older messages exist. |
errCode | number | Status code returned for this history request. |
errMsg | string | Status message corresponding to errCode. |
When merging messageList into the local conversation state, deduplicate entries by clientMsgID to prevent duplicate renders from asynchronous callbacks or network retries.
Was this page helpful?