Sanity Library Reference Docs
    Preparing search index...

    Function useUpdateUserPreference

    • Beta

      Changes a preference of the signed-in user, read with useUserPreference. A value shows at once and goes back if the API refuses it. undefined removes the user's value, so the key's default applies again. A function gets the value on screen and returns the next one, like a toggle.

      The options say where the value is stored, and only take the places the key is stored in. shared: true changes the value everyone in the project or organization shares, where the key has one. resourceType names the kind of resource, which a key stored in both projects and organizations needs. Without a projectId, it uses the project of the nearest resource; without an organizationId, the Dashboard's organization.

      Type Parameters

      • K extends PreferenceKey

      Parameters

      • key: K
      • Optionaloptions: UserPreferenceOptions<K>

      Returns MutationHookResult<PreferenceEdit<K>, UserPreference<K>>

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

      const {mutate: setLayout, error} = useUpdateUserPreference('studio.structure-tool.layout.book')
      setLayout('compact')
      setLayout((layout) => (layout === 'compact' ? 'detail' : 'compact'))
      setLayout(undefined)