Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript: useDrag & @react-three/fiber: Types of property 'onClick' are incompatible. MouseEventHandler vs ThreeEvent #374

Open
1 task done
timoxley opened this issue Oct 28, 2021 · 5 comments
Assignees
Labels
help wanted Extra attention is needed r3f related to react-three-fiber Typescript Error with types

Comments

@timoxley
Copy link

useDrag seems to work fine with @react-three/fiber components, but TypeScript complains about the handlers being attached by {...bind()}.

e.g.

  const bind = useDrag<ThreeEvent<MouseEvent>>(() => {})
  return <mesh {...bind()} />
 Types of property 'onClick' are incompatible.
    Type 'MouseEventHandler<EventTarget> | undefined' is not assignable to type '((event: ThreeEvent<MouseEvent>) => void) | undefined'.
      Type 'MouseEventHandler<EventTarget>' is not assignable to type '(event: ThreeEvent<MouseEvent>) => void'.
        Types of parameters 'event' and 'event' are incompatible.
          Type 'MouseEvent & IntesectionEvent<MouseEvent>' is missing the following properties from type 'MouseEvent<EventTarget, MouseEvent>': isDefaultPrevented, isPropagationStopped, persist

Sandbox

https://codesandbox.io/s/fervent-blackburn-3p8db?file=/src/index.tsx

Information:

  • React Use Gesture version: [e.g. v10.1.1]

Checklist:

@dbismut
Copy link
Collaborator

dbismut commented Oct 28, 2021

Please see: #287

There's no easy fix except from making bind() typings looser.

@dbismut dbismut added r3f related to react-three-fiber Typescript Error with types labels Oct 28, 2021
@timoxley
Copy link
Author

timoxley commented Oct 28, 2021

@dbismut Thanks David. Apologies for the duplicate.

I'm not sure how to solve this unless I create a package such as @use-gesture/r3f with proper types.

Yeah this was the solution I was thinking might be needed. Perhaps such a package would open the door to adding more specialised interfaces for THREE e.g.

  • bounds could take a Box3 | React.RefObject<Box3> as an analogue for HTMLElement | React.RefObject<HTMLElement>
  • axis take a Vec3
  • offset/movement could be automatically translated into world coordinates.
  • offset/movement could be calculated based on distance along a plane (axis) at the ray intersection point.
  • etc

Suggesting these things specifically because they're the useDrag features I had to reimplement when I converted my current project UI elements from using/abusing DOM+CSS transforms to r3f.

@dbismut
Copy link
Collaborator

dbismut commented Oct 28, 2021

I agree but I don't use r3f enough to know how to implement those. That would probably mean adding also another core package for DOM related packages.

@yoosif0
Copy link

yoosif0 commented Feb 10, 2023

any updates?

@rogersanick
Copy link

Also having this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed r3f related to react-three-fiber Typescript Error with types
Projects
None yet
Development

No branches or pull requests

4 participants