Created
May 11, 2019 18:47
-
-
Save ruucm/e16221da2424e319403220841267f301 to your computer and use it in GitHub Desktop.
Custom hook to listen MotionValue change of Framer X
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
import { useMemo } from 'react' | |
import { MotionValue } from 'framer' | |
var __assign = function() { | |
__assign = | |
Object.assign || | |
function __assign(t) { | |
for (var s, i = 1, n = arguments.length; i < n; i++) { | |
s = arguments[i] | |
for (var p in s) | |
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p] | |
} | |
return t | |
} | |
return __assign.apply(this, arguments) | |
} | |
const addChild = function(value, config) { | |
var child = new MotionValue(value.current, __assign({ parent: this }, config)) | |
if (!value.children) value.children = new Set() | |
value.children.add(child) | |
return child | |
} | |
function useMotionValueListen(value, listner) { | |
return useMemo(() => { | |
addChild(value, { | |
transformer: (() => { | |
return listner | |
})(), // using callback here | |
}) | |
}) | |
} | |
export default useMotionValueListen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use
MotionValue.prototype.onChange
instead