Skip to content

Commit

Permalink
Updating event type inference
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgperry authored and mergatron[bot] committed Dec 16, 2022
1 parent 177ab68 commit d59d3a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
@@ -0,0 +1,16 @@
import * as React from "react"
import { render } from "../../../jest.setup"
import { useMotionValue } from "../../value/use-motion-value"
import { useMotionValueEvent } from "../use-motion-value-event"

describe("useMotionValueEvent", () => {
test("useMotionValueEvent infers type for change callback", () => {
const Component = () => {
const x = useMotionValue(0)
useMotionValueEvent(x, "change", (latest) => latest / 2)
return null
}

render(<Component />)
})
})
2 changes: 1 addition & 1 deletion packages/framer-motion/src/utils/use-motion-value-event.ts
Expand Up @@ -5,7 +5,7 @@ export function useMotionValueEvent<
V,
EventName extends keyof MotionValueEventCallbacks<V>
>(
value: MotionValue,
value: MotionValue<V>,
event: EventName,
callback: MotionValueEventCallbacks<V>[EventName]
) {
Expand Down
6 changes: 6 additions & 0 deletions packages/framer-motion/src/value/__tests__/index.test.ts
Expand Up @@ -2,6 +2,12 @@ import { motionValue } from "../"
import { animate } from "../../animation/animate"

describe("motionValue", () => {
test("change event is type-inferred", () => {
const value = motionValue(0)

value.on("change", (latest) => latest / 2)
})

test("change event fires when value changes", () => {
const value = motionValue(0)
const callback = jest.fn()
Expand Down

0 comments on commit d59d3a1

Please sign in to comment.