Help & Support

Fetch Groups

This guide will help you with fetching Groups from Lens API.

Get a Group

Use the useGroup hook to fetch a single Group. Returns null if no group is found.

const { data, loading, error } = useGroup(request);

A Group can be fetched by its address or by transaction hash.

import { evmAddress, useGroup } from "@lens-protocol/react";
// …
const { data, loading, error } = useGroup({  group: evmAddress("0x1234…"),});
if (loading) {  return <p>Loading…</p>;}
if (error) {  return <p>{error.message}</p>;}
// data: Group | null

List Groups

Use the useGroups hook to fetch a list of Groups.

const { data, loading, error } = useGroups(request);

Groups can be fetched by search query, app address, managedBy or member.

import { useGroups } from "@lens-protocol/react";
// …
const { data, loading, error } = useGroups({  filter: {    searchQuery: "group",  },});
if (loading) {  return <p>Loading…</p>;}
if (error) {  return <p>{error.message}</p>;}
// data: Array<Group>

See the Pagination guide for more information on how to handle paginated results.