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
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
User sets a custom ID in the component's properties (e.g., "contact-form")
Your hook calls
rw.addAnchor('contact-form')The anchor appears in the link picker's Anchor menu
When selected, it creates a link like
#contact-formClicking the link scrolls to your component
Example with Fallback
Notes
Only call
addAnchorwhen you have a valid, non-empty IDThe anchor ID should match the
idattribute on your root elementAnchors 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?

