Common Scenarios
Learn how to handle common read scenarios involving Lens Publications.
Single Publication
Learn how to fetch a single publication using either its Publication ID or Transaction Hash.
- React SDK
- JavaScript SDK
- API
The usePublication and useLazyPublication hooks enable you to retrieve a specific Lens Publication using its ID or Transaction Hash.
Available in @lens-protocol/react-web and @lens-protocol/react-native
Multiple Publications
Fetch a list of publications based on specific criteria. You can filter by Publication IDs, Profile IDs, Types, Metadata, and more.
In the example below, we will retrieve only Post and Mirror publications, meaning we will query by publication type. Other types of queries are shown in the following sections.
- React SDK
- JavaScript SDK
- API
The usePublications and useLazyPublications are two hooks that allow you to retrieve multiple publications based on different criteria.
You can find the complete list of filters here.
Available in @lens-protocol/react-web and @lens-protocol/react-native
The usePublications hook returns a PaginatedReadResult<AnyPublication[]>. For more information on pagination, refer to this guide.
Publications by Profile
Retrieve all publications authored by a specific Profile ID.
- React SDK
- JavaScript SDK
- API
The usePublications and useLazyPublications are two hooks that allow you to retrieve multiple publications based on different criteria.
Publications.tsx
import { usePublications, profileId } from '@lens-protocol/react-web';
function Publications() { const { data, loading, error } = usePublications({ where: { from: [profileId("0x01")], }, });
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
return ( <div> {data.map((publication) => ( <div key={publication.id}>{publication.id}</div> ))} </div> );}
Retrieve all comments associated with a specific publication.
- React SDK
- JavaScript SDK
- API
The usePublications and useLazyPublications are two hooks that allow you to retrieve multiple publications based on different criteria.
Publications.tsx
import { usePublications, publicationId } from '@lens-protocol/react-web';
function Publications() { const { data, loading, error } = usePublications({ where: { commentOn: { id: publicationId("0x32-0x4e"), }, }, });
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
return ( <div> {data.map((publication) => ( <div key={publication.id}>{publication.id}</div> ))} </div> );}
Mirrors of a Publication
Retrieve all mirrors of a specific publication.
- React SDK
- JavaScript SDK
- API
The usePublications and useLazyPublications are two hooks that allow you to retrieve multiple publications based on different criteria.
Publications.tsx
import { usePublications, publicationId } from '@lens-protocol/react-web';
function Publications() { const { data, loading, error } = usePublications({ where: { mirrorOn: publicationId("0x03-0x24"), }, });
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
return ( <div> {data.map((publication) => ( <div key={publication.id}>{publication.id}</div> ))} </div> );}
Quotes of a Publication
Retrieve all quotes of a specific publication.
- React SDK
- JavaScript SDK
- API
The usePublications and useLazyPublications are two hooks that allow you to retrieve multiple publications based on different criteria.
Publications.tsx
import { usePublications, publicationId } from '@lens-protocol/react-web';
function Publications() { const { data, loading, error } = usePublications({ where: { quoteOn: publicationId("0x79-0x06"), }, });
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
return ( <div> {data.map((publication) => ( <div key={publication.id}>{publication.id}</div> ))} </div> );}
Publications by Content Focus
Retrieve all short-form video post publications.
- React SDK
- JavaScript SDK
- API
The usePublications and useLazyPublications are two hooks that allow you to retrieve multiple publications based on different criteria.
Publications.tsx
import { usePublications, PublicationType, PublicationMetadataMainFocusType } from '@lens-protocol/react-web';
function Publications() { const { data, loading, error } = usePublications({ where: { publicationTypes: [PublicationType.Post] metadata: { mainContentFocus: [PublicationMetadataMainFocusType.ShortVideo], } }, });
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
return ( <div> {data.map((publication) => ( <div key={publication.id}>{publication.id}</div> ))} </div> );}
That's it—you now have a solid understanding of how to retrieve Lens Publications in typical social app scenarios.
Comments for a Publication