---
title: "withState(_:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/animationcontext/withstate(_:)"
---

# withState(_:)

Creates a new context from another one with a state that you provide.

## Declaration

```swift
func withState<T>(_ state: AnimationState<T>) -> AnimationContext<T> where T : VectorArithmetic
```

## Parameters

- `state`: The initial state for the new context.

## Return Value

Return Value A new context that contains the specified state.

## Discussion

Discussion Use this method to create a new context that contains the state that you provide and view environment values from the original context.
