Skip to main content

Block ID Rules

Each Block must have an id attribute, and the value of this attribute must meet the following requirements:

  1. The id must be unique within the document
  2. 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