Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LinkControl docs with advice to memoize value prop #54659

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/block-editor/src/components/link-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ The resulting default properties of `value` include:
- `title` (`string`, optional): Link title.
- `opensInNewTab` (`boolean`, optional): Whether link should open in a new browser tab. This value is only assigned when not providing a custom `settings` prop.

Note: `<LinkControl>` maintains an internal state tracking temporary user edits to the link `value` prior to submission. To avoid unwanted syncroni`ation of this internal value, it is advised that the `value` prop passed to the component is stablized (likely via memozation) before it is passed to the component. This will avoid unwanted loss of any changes users have may made whilst interacting with the control.
getdave marked this conversation as resolved.
Show resolved Hide resolved

```jsx
const memoizedValue = useMemo(
() => ( {
url: attributes.url,
type: attributes.type,
opensInNewTab: attributes.target === '_blank',
title: attributes.text,
} ),
[
attributes.url,
attributes.type,
attributes.target,
attributes.text,
]
);

<LinkControl
value={ memoizedValue }
>
```

### settings

- Type: `Array`
Expand Down
Loading