Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function useTransform2(
mv1: MotionValue,
mv2: MotionValue,
transformer: (v1, v2) => any
) {
const mv = useMotionValue(0)
React.useEffect(() => {
const unsub1 = mv1.onChange(v1 => mv.set(transformer(v1, mv2.get())))
const unsub2 = mv2.onChange(v2 => mv.set(transformer(mv1.get(), v2)))
return () => {
unsub1()
unsub2()
}
}, [mv1, mv2, transformer, mv])
return mv
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment