Skip to content

Commit

Permalink
fix(ui-react-utils): fix ID counter wrong when not in context
Browse files Browse the repository at this point in the history
WIP, still needs unit tests
  • Loading branch information
matyasf committed Oct 10, 2023
1 parent 050c825 commit 40f4b75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import React from 'react'
import { generateInstanceCounterMap } from './generateInstanceCounterMap'

const DeterministicIdContext = React.createContext(generateInstanceCounterMap())
const defaultDeterministicIDMap = generateInstanceCounterMap()
const DeterministicIdContext = React.createContext(defaultDeterministicIDMap)

export { DeterministicIdContext }
export { DeterministicIdContext, defaultDeterministicIDMap }
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
* SOFTWARE.
*/
import React from 'react'
import { generateInstanceCounterMap } from './generateInstanceCounterMap'
import { DeterministicIdContext } from './DeterministicIdContext'
import {
DeterministicIdContext,
defaultDeterministicIDMap
} from './DeterministicIdContext'

type DeterministicIdProviderValue = Map<string, number>
type DeterministicIdProviderProps = React.PropsWithChildren<{
instanceCounterMap?: DeterministicIdProviderValue
}>

const defaultContextValue = generateInstanceCounterMap()

/**
* ---
* category: components/utilities
Expand All @@ -50,7 +51,7 @@ const DeterministicIdContextProvider = ({
)
}
DeterministicIdContextProvider.defaultProps = {
instanceCounterMap: defaultContextValue
instanceCounterMap: defaultDeterministicIDMap
}

export { DeterministicIdContextProvider }
Expand Down

0 comments on commit 40f4b75

Please sign in to comment.