Skip to content

Commit

Permalink
Update LinkControl docs with advice to memoize value prop (#54659)
Browse files Browse the repository at this point in the history
* Update docs

* Update reasoning

* Update wording to match review comment

* Actually update the text
  • Loading branch information
getdave authored Oct 5, 2023
1 parent 6fe6d2b commit 5735a49
Showing 1 changed file with 23 additions and 0 deletions.
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 synchronization of this internal value, it is advised that the `value` prop 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.

```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

0 comments on commit 5735a49

Please sign in to comment.