Sanity Library Reference Docs
    Preparing search index...

    Function useUpdateUserPreferenceList

    • Beta

      Saves one of the signed-in user's items for a key, like a saved query, read with useUserPreferenceList. It replaces the item with the same ID, and undefined removes it. Every page the list has read is read again once the API answers. Without a projectId, it uses the project of the nearest resource.

      Type Parameters

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

      Parameters

      • key: K
      • Optionaloptions: UserPreferenceOptions<K>

      Returns MutationHookResult<
          { itemId: string; value: PreferenceListItemValue<K>
          | undefined },
          void,
      >

      The mutation envelope {mutate, isPending, error, data, reset}. mutate resolves once the API has the change, or rejects with a PreferenceError when it refuses it.

      const {mutate: setQuery} = useUpdateUserPreferenceList('studio.vision-tool.saved-queries')
      setQuery({
      itemId: 'q1',
      value: {_key: 'q1', url: '?query=*[_type == "post"]', savedAt: new Date().toISOString()},
      })
      setQuery({itemId: 'q1', value: undefined})