Bookmarks
Learn how to bookmark a publication and access all your saved bookmarks.
The bookmarks feature allows a Profile to save references to publications. Each profile maintains a private list of bookmarks. As Lens Bookmarks are stored off-chain, they are instant and do not require signatures or gas to use.
You must be authenticated with a Profile to use bookmarks. See Profile Login for more information.
Bookmark a Publication
You can bookmark a publication for easy access later. If it's no longer needed, you can simply remove the bookmark.
- React SDK
- JavaScript SDK
- API
The useBookmarkToggle hook allows you to bookmark a Lens Publication. If the publication is already bookmarked, using this hook will remove the bookmark.
Available in @lens-protocol/react-web and @lens-protocol/react-native
import { AnyPublication, useBookmarkToggle } from '@lens-protocol/react-web';
function Publication({ publication }: { publication: AnyPublication }) { const { execute: toggle, loading } = useBookmarkToggle();
return ( <button onClick={() => toggle({ publication })} disabled={loading}> {publication.operations.hasBookmarked ? 'Bookmarked' : 'Not bookmarked'} </button> );}
Bookmarked Publications
To determine if a publication has been bookmarked by the logged-in profile, you can use the publication.operations.hasBookmarked property.
The publication.stats.bookmarks property of a publication indicates the number of times it has been bookmarked.
List All Bookmarks
You can retrieve all the publications bookmarked by the currently logged-in profile.
- React SDK
- JavaScript SDK
- API
Use the useBookmarks hook to retrieve all bookmarked publications.
Available in @lens-protocol/react-web and @lens-protocol/react-native
import { useBookmarks } from '@lens-protocol/react-web';
function Bookmarks() { const { data, loading, error } = useBookmarks();
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
if (data.length === 0) return <p>No bookmarks found</p>;
return ( <ul> {data.map((publication) => ( <li key={publication.id}>{publication.id}</li> ))} </ul> );}
The hook yields a PaginatedReadResult<AnyPublication[]>. For more information on pagination, refer to this guide.