Skip to content

Commit

Permalink
Updating useTransform to subscribe on layout effect (framer#1617)
Browse files Browse the repository at this point in the history
* Updating useTransform to subscribe on layout effect

* Removing console log
  • Loading branch information
mattgperry authored and utileetdulce committed Aug 10, 2022
1 parent 566e853 commit 31b0a45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,12 @@ Framer Motion adheres to [Semantic Versioning](http://semver.org/).

Undocumented APIs should be considered internal and may change without warning.

## [6.5.1] 2022-07-14

### Fixed

- Adding `onChange` handlers in `useTransform` on `useLayoutEffect`.

## [6.5.0] 2022-07-13

### Added
Expand Down
6 changes: 3 additions & 3 deletions packages/framer-motion/src/value/use-on-change.ts
@@ -1,18 +1,18 @@
import { useEffect } from "react"
import { useIsomorphicLayoutEffect } from "../three-entry"
import { MotionValue, Subscriber } from "./"
import { isMotionValue } from "./utils/is-motion-value"

export function useOnChange<T>(
value: MotionValue<T> | number | string,
callback: Subscriber<T>
) {
useEffect(() => {
useIsomorphicLayoutEffect(() => {
if (isMotionValue(value)) return value.onChange(callback)
}, [callback])
}

export function useMultiOnChange(values: MotionValue[], handler: () => void) {
useEffect(() => {
useIsomorphicLayoutEffect(() => {
const subscriptions = values.map((value) => value.onChange(handler))
return () => subscriptions.forEach((unsubscribe) => unsubscribe())
})
Expand Down

0 comments on commit 31b0a45

Please sign in to comment.