Block Editor: Add hook: useNoRecursiveRenders#28428
Conversation
Originally introduced in #28405 to prevent Reusable Blocks from infinitely and fatally recurring, React hook `useNoRecursiveRenders` has a place in the block-editor package so that other block types susceptible to recursion can be fixed too.
|
Size Change: +42 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
gziolo
left a comment
There was a problem hiding this comment.
Thank you for opening a follow-up ❤️
Tests work so we can ship I think 🚢
| return result; | ||
| } | ||
|
|
||
| export default function useNoRecursiveRenders( uniqueId ) { |
There was a problem hiding this comment.
JSDoc comment with an example should help create README.md once it gets promoted stable. In addition, it will make it easier to type the package with TS in the future.
There was a problem hiding this comment.
How's this? 1c3b036
I'm not familiar with our latest typing practice. Do you have a specific React type you recommend for the returned provider? For now I just used Function.
There was a problem hiding this comment.
Yes, this is exactly what I meant 👍🏻
If you think it deserves an example, you can use the following syntax:
gutenberg/packages/plugins/src/components/plugin-area/index.js
Lines 38 to 50 in 1608a02
Description
Follows up on #28405.
Originally introduced in #28405 to prevent Reusable Blocks from infinitely and fatally recurring, React hook
useNoRecursiveRendershas a place in theblock-editorpackage so that other block types susceptible to recursion can be fixed too.This hook is marked as experimental, available under the name
__experimentalUseNoRecursiveRenders.Along with the move, the hook was refactored to:
ref(an allusion to therefattribute of Reusable Blocks) becomesuniqueId.Setinstead ofArrayto keep track of previously rendered blocks.How has this been tested?
This change should have no observable effects.
Types of changes
Refactor; new API
Checklist: