Ts-sdk messages pagination not working

So, I followed the code here → RunQuery Pattern - Amity Docs however, not receiving the next set of messages, instead just receiving the same messages again and again.

export const useMessages = channelId => {
  const [messages, setMessages] = useState([]);
  const [options, setOptions] = useState();

  const {loading, nextPage, error} = options ?? {};

  const onQueryMessages = useCallback(
    ({reset = false, page = {limit: 5}}) => {
      const query = createQuery(queryMessages, {page, channelId});

      runQuery(query, ({data, ...rest}) => {
        if (data) {
          // setMessages(prevPosts => (reset ? constructMessageObj(data) : [...prevPosts, ...constructMessageObj(data)]));
          setMessages(prevMessages => {
            let messageArray = [];
            for (let messageData of data) {
              messageArray.push(constructMessageObj(messageData));
            }
            return reset ? messageArray.reverse() : [...prevMessages, ...messageArray].reverse();
          });
        }

        setOptions(rest);
      });
    },
    [channelId],
  );

  useEffect(() => onQueryMessages({reset: true}), [onQueryMessages]);

  const loadMore = () => {
    if (nextPage) {
      onQueryMessages({page: nextPage});
    }
  };

  return [messages, loadMore];
};

Hello @maknom66 Sorry for the late response, the team is looking into this and I will keep you posted :pray: Thank you.

Hi @maknom66 you will have to pass page options when you query message, then it should return the next page. Please see the sample code below :pray: thank you.

const useMessages = (channelId) => {
const [messages, setMessages] = useState([])
const [options, setOptions] = useState()

useEffect(() => {
onQueryMessages({ channelId: channelId })
}, [])

useEffect(() => {
if (options != null && options.prevPage!= null && options.prevPage.before > 0) {
onQueryMessages({ channelId: channelId, page: options.prevPage })
}
}, [options])

const onQueryMessages = ({
channelId = '',
reset = false,
page = { limit: 5 },
}) => {
const query = createQuery(queryMessages, { page, channelId })

runQuery(query, ({ data, ...rest }) => {
  if (data) {
    setMessages((prevPosts) => (reset ? data : [...prevPosts, ...data]))
    setOptions(rest)
  }
})

}
}

Please check your API once, even if I pass correct page params, I am not getting correct messages as a result.

Hi @maknom66 sorry for late response, the team has re-checked the code and would recommend you to use prevPage instead, they updated the sample code in this link RunQuery Pattern - Amity Docs if the issue still exists, please let us know :pray: