rsnext/examples/with-slate/lib/useCustomKeygen.js
2019-09-02 13:00:15 -05:00

14 lines
342 B
JavaScript

import { useRef } from 'react'
import { KeyUtils } from 'slate'
const useCustomKeygen = uniqueKey => {
const ref = useRef(null)
if (!ref.current || ref.current !== uniqueKey) {
let n = 0
const keygen = () => `${uniqueKey}${n++}`
KeyUtils.setGenerator(keygen)
ref.current = uniqueKey
}
}
export default useCustomKeygen