Skip to content

Commit

Permalink
fix: [popper]修复问题添加单测
Browse files Browse the repository at this point in the history
  • Loading branch information
hxh2010 authored and haohao_peng committed Apr 24, 2024
1 parent 17af0aa commit ef33f41
Show file tree
Hide file tree
Showing 5 changed files with 836 additions and 96 deletions.
40 changes: 40 additions & 0 deletions components/_utils/useId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from 'react'

function getUseId() {
const fullClone: any = {
...React,
}

return fullClone?.useId
}

let uuid = 0

const useOriginId = getUseId()

export default useOriginId
? function useId(id?: string) {
const reactId = useOriginId()

if (id) {
return id
}

return reactId
}
: function useCompatId(id?: string) {
const [innerId, setInnerId] = React.useState<string>('ssr-id')

React.useEffect(() => {
const nextId = uuid
uuid += 1

setInnerId(`kd_unique_${nextId}`)
}, [])

if (id) {
return id
}

return innerId
}
Loading

0 comments on commit ef33f41

Please sign in to comment.