Skip to content

Instantly share code, notes, and snippets.

@ruucm
Created May 11, 2019 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruucm/e16221da2424e319403220841267f301 to your computer and use it in GitHub Desktop.
Save ruucm/e16221da2424e319403220841267f301 to your computer and use it in GitHub Desktop.
Custom hook to listen MotionValue change of Framer X
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
@ruucm
Copy link
Author

ruucm commented May 11, 2019

use MotionValue.prototype.onChange instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment