SwiftUI.js
Components

ScrollViewReader

ScrollViewReader exposes a proxy that can scroll to child `ScrollTarget` anchors by identifier.

ScrollViewReader exposes a proxy that can scroll to child `ScrollTarget` anchors by identifier.

Examples

Basic Usage

Preview unavailable for this example in the static docs build.

Show code
<ScrollViewReader>
      {(proxy) => (
        <VStack spacing={12}>
          <Button onClick={() => proxy.scrollTo('details', { behavior: 'smooth', block: 'nearest' })}>
            Jump to details
          </Button>
          <ScrollView style={{ height: '220px' }}>
            <VStack spacing={16}>
              <ScrollTarget scrollId="summary">
                <div style={{ minHeight: '180px' }}>Summary section</div>
              </ScrollTarget>
              <ScrollTarget scrollId="details">
                <div style={{ minHeight: '180px' }}>Details section</div>
              </ScrollTarget>
            </VStack>
          </ScrollView>
        </VStack>
      )}
    </ScrollViewReader>

API

PropTypeRequiredDescription
children(proxy: IScrollViewProxy) => React.ReactNodeYesNo description yet.

Inherits additional props from Omit<IBaseComponent, 'children'>.

Overview

ScrollViewReader exposes a proxy that can scroll to child ScrollTarget anchors by identifier.

Status: adapted

SwiftUI Correspondence: Adapted from SwiftUI's ScrollViewReader.

Notes

  • scrollTo(id) resolves descendants marked with ScrollTarget
  • the current web adaptation uses scrollIntoView() under the hood
  • keep target identifiers stable across renders so imperative scrolling remains deterministic

On this page