Skip to content

Commit

Permalink
Adds example for useBlockProps hook (#53646)
Browse files Browse the repository at this point in the history
  • Loading branch information
mburridge authored Aug 17, 2023
1 parent 4b5c0da commit 3d50e45
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,31 @@ _Returns_

This hook is used to lightly mark an element as a block element. The element should be the outermost element of a block. Call this hook and pass the returned props to the element to mark as a block. If you define a ref for the element, it is important to pass the ref to this hook, which the hook in turn will pass to the component through the props it returns. Optionally, you can also pass any other props through this hook, and they will be merged and returned.

Use of this hook on the outermost element of a block is required if using API >= v2.

_Usage_

```js
import { useBlockProps } from '@wordpress/block-editor';

export default function Edit() {

const blockProps = useBlockProps(
className: 'my-custom-class',
style: {
color: '#222222',
backgroundColor: '#eeeeee'
}
)

return (
<div { ...blockProps }>

</div>
)
}
```

_Parameters_

- _props_ `Object`: Optional. Props to pass to the element. Must contain the ref if one is defined.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ const BLOCK_ANIMATION_THRESHOLD = 200;
* also pass any other props through this hook, and they will be merged and
* returned.
*
* Use of this hook on the outermost element of a block is required if using API >= v2.
*
* @example
* ```js
* import { useBlockProps } from '@wordpress/block-editor';
*
* export default function Edit() {
*
* const blockProps = useBlockProps(
* className: 'my-custom-class',
* style: {
* color: '#222222',
* backgroundColor: '#eeeeee'
* }
* )
*
* return (
* <div { ...blockProps }>
*
* </div>
* )
* }
*
* ```
*
*
* @param {Object} props Optional. Props to pass to the element. Must contain
* the ref if one is defined.
* @param {Object} options Options for internal use only.
Expand Down

1 comment on commit 3d50e45

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 3d50e45.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5889297771
📝 Reported issues:

Please sign in to comment.