Created
September 16, 2019 20:32
-
-
Save lintonye/3cfea524aa0bd91d962ef22c5445d1a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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