---
title: "updateAnchors"
description: "Update the anchors."
type: "function"
---
## API Reference

### updateAnchors

> Source set: Common

```kotlin
public fun updateAnchors(
        newAnchors: DraggableAnchors<T>,
        newTarget: T =
            if (!offset.isNaN()) {
                newAnchors.closestAnchor(offset) ?: targetValue
            } else targetValue,
    )
```

Update the anchors. If there is no ongoing [anchoredDrag](/jetpack-compose/androidx.compose.foundation/foundation/functions/anchoredDrag/api) operation, snap to the `newTarget`,
otherwise restart the ongoing [anchoredDrag](/jetpack-compose/androidx.compose.foundation/foundation/functions/anchoredDrag/api) operation (e.g. an animation) with the new
anchors.

<b>If your anchors depend on the size of the layout, updateAnchors should be called in the
layout (placement) phase, e.g. through Modifier.onSizeChanged.</b> This ensures that the
state is set up within the same frame. For static anchors, or anchors with different data
dependencies, [updateAnchors](/jetpack-compose/androidx.compose.foundation/foundation/functions/updateAnchors/api) is safe to be called from side effects or layout.

#### Parameters

| | |
| --- | --- |
| newAnchors | The new anchors. |
| newTarget | The new target, by default the closest anchor or the current target if there are no anchors. |
