Sanity Library Reference Docs
    Preparing search index...

    Function useUserPreferenceList

    • Beta

      Reads the signed-in user's items for a key, like their saved queries, a page at a time. Suspends until the user and the first page are known; loadMore adds the next page while the list stays on screen. After a change, every page read so far is read again from the first, so an item never shows twice or goes missing. Without a projectId, it uses the project of the nearest resource. Change the items with useUpdateUserPreferenceList.

      Type Parameters

      • K extends "studio.vision-tool.saved-queries"

      Parameters

      • key: K
      • Optionaloptions: UserPreferenceOptions<K>

      Returns UserPreferenceListResult<K>

      const {data, hasMore, isPending, loadMore} = useUserPreferenceList(
      'studio.vision-tool.saved-queries',
      )
      return (
      <>
      {data.map(({itemId, value}) => <li key={itemId}>{value.title ?? value.url}</li>)}
      {hasMore && <button onClick={loadMore} disabled={isPending}>Load more</button>}
      </>
      )