Last active
April 28, 2025 07:52
-
-
Save ozbeksu/4873ad5d65f6770079edf9a000028a6c to your computer and use it in GitHub Desktop.
PayloadCMS Revursive Block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Block} from 'payload/types'; | |
const createRecursiveLinksBlock = (current = 0, maxDepth = 3): Block => { | |
if (current < maxDepth - 1) { | |
current++; | |
return { | |
slug: `Level ${current}`, | |
fields: [ | |
{ | |
name: 'name', | |
type: 'text', | |
}, | |
{ | |
name: 'children', | |
type: 'blocks', | |
blocks: [createRecursiveLinksBlock(current)], | |
}, | |
], | |
}; | |
} | |
return { | |
slug: `Level ${current + 1}`, | |
fields: [ | |
{ | |
name: 'name', | |
type: 'text', | |
}, | |
], | |
}; | |
}; | |
const LinkBlock: Block = createRecursiveLinksBlock(); | |
export default LinkBlock; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment