-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix React error in @wordpress/block-editor docs usage example caused by applying args to setState call #25492
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
Conversation
This avoids the error as shown in #25333
|
Size Change: -548 B (0%) Total Size: 1.18 MB
ℹ️ View Unchanged
|
|
@cpapazoglou Pinging you for review here until you are a member of |
|
Thanks @getdave for you great PR & Issue description and for taking time to fix the docs! Apart from that, LGTM! |
mkaz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks! 👍
|
Thanks @mkaz. I'll merge this asap. |
|
Oh it's already merged 🤷 |
Fix for #25333
This updates the documented usage example for the
@wordpress/block-editordocs to avoid showing the following error in the consoleThis is happening because
onInputandonChangehandlers are called with x2 args:Supplying the
useStatehook's update handler (ie:updateBlocks) as the callback causes it to be called with the two arguments applied to it. UnfortunatelyuseStateonly expects a single argument which results in the error shown above.This PR updates to docs to use an arrow function to ensure only a single argument is passed to the
setStatecall which fixes the error. We could get fancy with partial application but for the purposes of documentation, a wrapper function is probably the easiest to understand.How has this been tested?
You can verify two args are provided to
onInputandonChangein the associated tests for the relevant components:gutenberg/packages/block-editor/src/components/provider/test/use-block-sync.js
Lines 237 to 239 in f12c563
Other than that you'd have to test up a test environment which I haven't had the chance to do.
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: