In a scenario where a function that is listening on a facet is calling another function created with useFacetCallback, the value of the same facet inside the second callback might be outdated.
For example:
const facet = createFacet({ initialValue: 'old value' })
function Comp() {
// Since this is run on useLayoutEffect, it will
// add the
const callback = useFacetCallback((value) => value, [], [facet])
// Since this is run on render, it will add the
// `.observe` subscription first
useMemo(() => {
facet.observe((value) => {
console.log('here be new value: ', value)
console.log('...and here is still old value: ', callback())
})
})
return null
}
facet.set('new value')