Common Scenarios
Learn strategies for handling common scenarios involving Lens Profiles.
Single Profile
Retrieve a specific Lens Profile.
- React SDK
- JavaScript SDK
- API
The useProfile and useLazyProfile hooks enable you to retrieve a specific Lens Profile using its Handle or ID.
Available in @lens-protocol/react-web and @lens-protocol/react-native
Fetch a Profile by Handle.
Fetch a Profile by ID.
Multiple Profiles
Retrieve multiple Lens Profiles by different criteria.
- React SDK
- JavaScript SDK
- API
The useProfiles and useLazyProfiles are two versatile hooks that allow you to retrieve multiple profiles based on different criteria.
Available in @lens-protocol/react-web and @lens-protocol/react-native
Fetch multiple Profiles by their Handles.
Fetch multiple Profiles by their IDs.
Fetch multiple Profiles by their owner addresses.
Fetch all Profiles who have mirrored a specific publication.
Fetch all Profiles who have commented on a specific publication.
Fetch all Profiles who have quoted a specific publication.
The useProfiles hook yields a PaginatedReadResult<Profile[]>. For more information on pagination, refer to this guide.
Collectors
Retrieve all Profiles that have collected a specific publication.
- React SDK
- JavaScript SDK
- API
You can use the useWhoActedOnPublication hook for this purpose.
Available in @lens-protocol/react-web and @lens-protocol/react-native
import { useWhoActedOnPublication, OpenActionCategoryType, publicationId,} from '@lens-protocol/react-web';
export function PublicationCollectors() { const { data, loading, error } = useWhoActedOnPublication({ on: publicationId('0x56-0x02'), where: { anyOf: [ { category: OpenActionCategoryType.Collect, }, ], }, });
if (loading) return <p>Loading...</p>;
if (error) return <p>Error fetching publication collectors: {error.message}</p>;
if (data.length === 0) return <p>Nobody has collected this publication.</p>;
return ( <ul> {data.map((profile) => ( <li key={profile.id}>{profile.handle?.fullHandle ?? profile.id}</li> ))} </ul> );}
The hook returns PaginatedReadResult<Profile[]>. For more information on pagination, refer to this guide.
Reaction Insight
Retrieve all Profiles that have reacted to a specific publication.
- React SDK
- JavaScript SDK
- API
You can use the useWhoReactedToPublication hook for this purpose.
Available in @lens-protocol/react-web and @lens-protocol/react-native
import { publicationId, useWhoReactedToPublication } from '@lens-protocol/react-web';
export function PublicationReactions() { const { data, loading, error } = useWhoReactedToPublication({ for: publicationId('0x56-0x02'), });
if (loading) return <p>Loading...</p>;
if (error) return <p>Error fetching who reacted to publication: {error.message}</p>;
if (data.length === 0) return <p>No profiles have reacted to this publication.</p>;
return ( <ul> {data.map((profileWhoReactedResult) => ( <li key={profileWhoReactedResult.profile.id}> <span> Profile: {profileWhoReactedResult.profile.handle?.fullHandle ?? profileWhoReactedResult.profile.id} </span> <div> Reactions: <ul> {profileWhoReactedResult.reactions.map((reaction) => ( <li key={reaction.reaction}> {reaction.reaction} at {reaction.reactionAt} </li> ))} </ul> </div> </li> ))} </ul> );}
The hook returns PaginatedReadResult<ProfileWhoReactedResult[]>. For more information on pagination, refer to this guide.
That's it—you now have a solid understanding of how to retrieve Lens Profiles in typical social app scenarios.