• Search for publications based on a defined criteria.

    Search for publications with content that contains "foo"

    const { data, error, loading } = useSearchPublications({ query: 'foo' });

    if (loading) return <Loader />;

    if (error) return <Error message={error.message} />;

    return (
    <>
    {data.map((publication) => (
    <PublicationCard key={publication.id} publication={publication} />
    ))}
    </>
    );

    Search for audio post publications with content that matches a query

    const { data, error, loading } = useSearchPublications({
    query: '...',
    where: {
    publicationTypes: [SearchPublicationType.Post],
    metadata: {
    mainContentFocus: [PublicationMetadataMainFocusType.Audio],
    },
    },
    });

    if (loading) return <Loader />;

    if (error) return <Error message={error.message} />;

    return (
    <>
    {data.map((publication) => (
    <PublicationCard key={publication.id} publication={publication} />
    ))}
    </>
    );

    Parameters

    Returns PaginatedReadResult<PrimaryPublication[]>

  • Experimental

    Search for publications based on a defined criteria.

    This signature supports React Suspense.

    const { data } = useSearchPublications({
    query: 'foo',
    suspense: true,
    });

    console.log(data);

    Use startTransition to avoid to re-suspend the component.

    const [query, setQuery] = useState('foo');

    const { data } = useSearchPublications({
    query,
    suspense: true,
    });

    const search = () => {
    startTransition(() => {
    setQuery('bar');
    });
    };

    This API can change without notice

    Returns SuspensePaginatedResult<PrimaryPublication[]>