-
-
Save HendrikRoth/3af99b236dcfebe20b2292316803d7bb 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