Skip to content

Commit

Permalink
Updating useTransform to subscribe on layout effect (#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 committed Jul 14, 2022
1 parent 9824840 commit d8f0be2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 d8f0be2

Please sign in to comment.