mousetrap icon indicating copy to clipboard operation
mousetrap copied to clipboard

bindGlobal is not a function

Open TurbulentCupcake opened this issue 5 years ago • 3 comments

I installed Mousetrap through npm and used it in my react code as follows: import * as Mousetrap from 'mousetrap'; . . . componentDidMount () { Mousetrap.bindGlobal('enter', this.submitSearch); However, this returns the following issue: Uncaught TypeError: mousetrap__WEBPACK_IMPORTED_MODULE_13__.bindGlobal is not a function

Is there a way around this?

TurbulentCupcake avatar May 14 '19 05:05 TurbulentCupcake

You need to use mousetrap-global-bind since it is a plugin.

haykam821 avatar Jun 13 '19 18:06 haykam821

Since the bindGlobal code is included in the normal NPM download, shouldn't there be a way to do it without going to the other NPM package?

browner12 avatar Jul 29 '19 17:07 browner12

@browner12 You can import it, like this:

import Mousetrap from 'mousetrap';
import 'mousetrap/plugins/global-bind/mousetrap-global-bind';

dinhtungdu avatar Aug 06 '19 10:08 dinhtungdu

@TurbulentCupcake Please close this issue as completed.

adil62 avatar Feb 16 '23 08:02 adil62