rw.addAnchor

The rw.addAnchor() function registers a custom anchor ID for your component, making it available in the link picker's "Anchor" menu so users can link directly to this component.

Syntax

rw.addAnchor(anchorId);

Parameters

Parameter
Type
Description

anchorId

String

The anchor ID to register (without the # symbol)

Basic Example

const transformHook = (rw) => {
    const { customId } = rw.props;
    
    if (customId && customId.length > 0) {
        rw.addAnchor(customId);
    }
};

exports.transformHook = transformHook;

Complete Pattern

When using anchors, you typically also need to set the id attribute on the root element:

How It Works

  1. User sets a custom ID in the component's properties (e.g., "contact-form")

  2. Your hook calls rw.addAnchor('contact-form')

  3. The anchor appears in the link picker's Anchor menu

  4. When selected, it creates a link like #contact-form

  5. Clicking the link scrolls to your component

Example with Fallback

Notes

  • Only call addAnchor when you have a valid, non-empty ID

  • The anchor ID should match the id attribute on your root element

  • Anchors are automatically available to other pages in the same project

  • Users can link to anchors using the standard link picker interface

Last updated

Was this helpful?