Callback function in custom hook is not reruning

const selectedValueSet = new Set(selectedValues) const [selectedValues] = useSelectedValues(undefined, (value)=> selectedValueSet.has(value.id)|| undefined)

in this hook, when the selectedValueSet changes the callback is not rerunnng. it takes the initial value of selectedValueSet.

I dont want to modify the hook, but looking for a way to get updated value for selectedValues as selectedValueSet changes. basically I wanna see if theres a way of re-running the callback when selectedValueSet changes

I tried logging the value inside the callback,

but the value only gets logged once, so as I understand this callback only runs once even if the selectedValueSet changes