Skip to content

Commit

Permalink
Add JSDoc comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed Jan 22, 2021
1 parent 16d76da commit 1c3b036
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ function add( set, element ) {
return result;
}

/**
* A React hook for keeping track of blocks previously rendered up in the block
* tree. Blocks susceptible to recursiion can use this hook in their `Edit`
* function to prevent said recursion.
*
* @param {*} uniqueId Any value that acts as a unique identifier for a block instance.
*
* @return {[boolean, Function]} A tuple of:
* - a boolean describing whether the provided id
* has already been rendered;
* - a React context provider to be used to wrap
* other elements.
*/
export default function useNoRecursiveRenders( uniqueId ) {
const previouslyRenderedBlocks = useContext( RenderedRefsContext );
const hasAlreadyRendered = previouslyRenderedBlocks.has( uniqueId );
Expand Down

0 comments on commit 1c3b036

Please sign in to comment.