Skip to content

Commit

Permalink
adding useTransform
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgperry committed Nov 19, 2018
1 parent 71c5ea7 commit 86d1ffc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -37,6 +37,7 @@
"webpack-dev-server": "^3.1.10"
},
"dependencies": {
"@popmotion/popcorn": "^0.2.0",
"hey-listen": "^1.0.5",
"popmotion": "^8.5.2",
"stylefire": "^2.3.1"
Expand Down
22 changes: 22 additions & 0 deletions src/hooks/use-transform.ts
@@ -0,0 +1,22 @@
import { useMemo, useRef } from 'react';
import { MotionValue } from '../motion-value';
import { interpolate } from '@popmotion/popcorn';

export default (
value: MotionValue,
from: number[],
to: string[] | number[]
) => {
const transformedValue = useRef(null);

return useMemo(
() => {
if (transformedValue.current) transformedValue.current.destroy();
transformedValue.current = value.addChild({
transformer: interpolate(from, to)
});
return transformedValue.current;
},
[value, ...from, ...to]
);
};

0 comments on commit 86d1ffc

Please sign in to comment.