Block ID Rules
Each Block must have an id attribute, and the value of this attribute must meet the following requirements:
- The id must be unique within the document
- The character length must be at least 9 characters, and the character range: a-z A-Z 0-9
You can use a third-party library: https://github.com/ai/nanoid
Reference code
import { customAlphabet } from 'nanoid'
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_', 8)
const SafeIdLeadCharacter = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
function randomCharacter() {
return SafeIdLeadCharacter[Date.now() % SafeIdLeadCharacter.length]
}
const genId = () => `${randomCharacter()}${nanoid()}`
export default genId