AppStorage

A property wrapper type that reflects a value from UserDefaults and invalidates a view on a change in value in that user default.

ComponentiOS 14.0+macOS 11.0+tvOS 14.0+watchOS 7.0+AppStorage in SwiftUI

Declaration

React
import { AppStorage } from 'swiftui-react-native';
Swift
@frozen @propertyWrapper struct AppStorage<Value>

Initializers

8 SwiftUI initializers back <AppStorage>. The props you pass pick one.

React
<AppStorage
  wrappedValue: string
  swiftKey: string
  store?: string | null
>
  children: (value: string, setValue: (value: string) => Promise<void>) => ReactNode
</AppStorage>
Swift
init(
    wrappedValue: Value,
    _ key: String,
    store: UserDefaults? = nil
)
where Value == URL
  • children*(value: string, setValue: (value: string) => Promise<void>) => ReactNode

    Renders the value, again whenever it changes.

  • wrappedValue*string

    The default value if a url value is not specified for the given key.

  • swiftKey*string

    The key to read and write the value to in the user defaults store.

    Swift key: String

  • storestring | null

    The user defaults store to read and write to. A value of nil will use the user default store from the environment.

    Default `nil`

Also takes the common view props: modifiers, style and testID.

See also

More in State and environment.