Search code examples
typescriptkonvajskonva

konva 2D drawing - can i send another variable in mouse down event?


I want to send another value in mouse event, because my handleMouseDown function is in another file.

stage.on('mousedown', handleMouseDown(evt, stage))

but i got error:

- Argument of type 'void' is not assignable to parameter of type 'KonvaEventListener<Stage, MouseEvent>'.ts(2345)
- Cannot find name 'evt'.ts(2304)

i tryed export my stage from init file, and import in another file but i not be able to export value from export default

import { handleMouseDown } from './stageEvents'
export default (): void => {
  export const stage: Stage = new Konva.Stage({
    container: 'container',
    height: 500,
    width: 500
  })
  // bind stage event
  stage.on('mousedown', handleMouseDown)

error: Modifiers cannot appear here

Does anyone have an some idea please?


Solution

  • You may want to do this:

    stage.on('mousedown', (evt) => handleMouseDown(evt, stage));