Skip to content

A code snippet is missing braces, which leads to an error in the console. #1563

Open

Description

Here in the useBlockProps usage example, the snippet is missing braces, which generates an error in the console.

Issue Description

The current code snippet using useBlockProps is:

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

The useBlockProps hook expects an object as a parameter. The snippet is missing braces, so the correct version should be:

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

For reference, another snippet on this doc correctly demonstrates the usage of the useBlockProps hook.

URL of the Page with the Issue

https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops

Section of Page with the issue

The section is: useBlockProps

Why is this a problem?

The snippet throws an error for missing braces.

Suggested Fix

Pass parameters in the useblockprops hook as an object.
I've created a pull request with the solutions: WordPress/gutenberg#61839

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions