Skip to main content

Overview

The useLatestNews hook fetches the latest news articles from the Sui blockchain registry and retrieves their full content from Walrus storage. It automatically includes engagement data (tips and comments) for each article.

Function Signature

function useLatestNews(limit?: number): UseQueryResult<NewsArticle[], Error>

Parameters

limit
number
default:"100"
Maximum number of articles to fetch. Articles are returned in reverse chronological order (newest first).

Return Type

Returns a React Query UseQueryResult object containing:
data
NewsArticle[]
Array of news articles with full content and engagement data
id
string
Unique identifier for the article (same as blob_id)
blob_id
string
Walrus blob ID containing the article content
title
string
Article title
category
string
Article category (currently defaults to ‘General’)
source
'twitter' | 'rss' | 'onchain'
Source of the article
timestamp
number
Unix timestamp when the article was published
content
string
Full article content fetched from Walrus
summary
string
Article summary or excerpt
url
string
Original article URL
image
string
Article cover image URL
author
string
Article author name
totalTips
number
Total tips received in SUI tokens
tipCount
number
Number of tips received
commentCount
number
Number of comments on the article
isLoading
boolean
Whether the query is currently loading
error
Error | null
Error object if the query failed
refetch
() => Promise<void>
Function to manually refetch the articles

Usage

import { useLatestNews } from '@tuna/sdk';

function NewsFeed() {
  const { data: articles, isLoading, error } = useLatestNews();

  if (isLoading) return <div>Loading articles...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return (
    <div>
      {articles?.map((article) => (
        <article key={article.id}>
          <h2>{article.title}</h2>
          <p>{article.summary}</p>
          <div>
            <span>💰 {article.totalTips} SUI</span>
            <span>💬 {article.commentCount} comments</span>
          </div>
        </article>
      ))}
    </div>
  );
}

Query Configuration

The hook is configured with the following React Query options:
  • Query Key: ['latestNews', limit]
  • Stale Time: 30 seconds (data is considered fresh for 30 seconds)
  • Caching: Automatically cached by React Query based on the limit parameter
The hook fetches articles in batches and retrieves full content from Walrus for each article. This may take a few seconds for large limit values.

Error Handling

If individual articles fail to fetch, they are filtered out of the results. The hook will return all successfully fetched articles rather than failing completely.
const { data: articles, error } = useLatestNews();

// articles may contain fewer items than the limit
// if some articles failed to fetch
if (articles) {
  console.log(`Successfully fetched ${articles.length} articles`);
}

See Also

Build docs developers (and LLMs) love