Browse SDKs · React Native
Platform
SDKsReact Native

Load older messages

Load historical messages backward in time with pagination using the OpenIM React Native SDK.

Copy

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

ParameterTypeRequiredDescription
conversationIDstringYesTarget conversation ID.
startClientMsgIDstringYesAnchor client message ID; pass an empty string "" for the initial page.
countnumberYesMaximum number of messages to fetch in this batch.
viewTypeViewTypeYesRetrieval context; pass ViewType.History when browsing standard chat logs.

Return value

A resolved Promise returns an AdvancedGetMessageResult object:

FieldTypeDescription
messageListMessageItem[]Array of historical messages for the current page, sorted chronologically.
isEndbooleanIndicates whether pagination has reached the earliest message; true means no older messages exist.
errCodenumberStatus code returned for this history request.
errMsgstringStatus 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.