简体   繁体   中英

How to apply mixpanel on event 'triggering' of dropdown in antdesign

I am working on a react application where on the click of dropdown menu in Antdesign(when Menu opens), I have to apply mixpanel. Now the dropdown has a trigger props, which expects a string, "click". This could be a basic concept in javascript, but I am new to Javascript/react, so any help is appreciated.

While passing the props 'trigger' down to Dropdown, instead of writing

trigger="click"

I wrote a function returning "click" and having mixpanel functionality, but it won't work as trigger expects PropTypes.string while I am passing function(PropTypes.func).

<Dropdown
visible={visible}
onSelect={onSelect}
/* And other props */
// trigger="click"
trigger={handleTrigger}    I know this isn't correct, but I want 
                           somewhat this type of functionality
/>

The handleTrigger function is -

const handleTrigger=()=>{
// MixPanel event handling
return "click"
}

On writing above code doesn't give errors, but the dropdown functionality is not working.

You are passing down a function and not executing it, in order for that to work you should try to do it like this :

trigger={this.handleTrigger()}

this way you are passing down to the props the execution of the function and not the function itself

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM