raveclassic/frp-ts

usePropertyFromProps inconsistency

Opened this issue · 0 comments

Hi @raveclassic!

There is a problem with usePropertyFromProps - the atom changes after the render and at the moment of the react props change prop !== prop$.get():

const Component = ({ prop }) => {
  const prop$ = usePropertyFromProps(prop)
  
  prop$.get() === prop // false at the moment of the props change 
}

Isn't it better to use the following implementation:

function usePropertyFromProps<Value>(value: Value): Property<Value> {
  const atomRef = useRef(newAtom(value))
  atomRef.current.set(value)
  return atomRef.current
}