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

Unable to get ContextMenu working (HOC style) #3891

Closed
Svenito opened this issue Dec 13, 2019 · 4 comments · Fixed by #4524
Closed

Unable to get ContextMenu working (HOC style) #3891

Svenito opened this issue Dec 13, 2019 · 4 comments · Fixed by #4524

Comments

@Svenito
Copy link

Svenito commented Dec 13, 2019

Environment

Question

Using the higher order component example from the docs, I am unable to get the ContextMenu to work. The error I am getting is

TypeError: Class constructor RightClickMeWithContext cannot be invoked without 'new'

Full error page:
https://pastebin.com/9N7Uusrb

I am using a create-react-app project, hence the HOC solution.

My component:

import React from "react";
import { ContextMenuTarget, Menu, MenuItem } from "@blueprintjs/core";

export const RightClickMe = ContextMenuTarget(
  class RightClickMeWithContext extends React.Component {
    render() {
      // root element must support `onContextMenu`
      return <div>TEST</div>;
    }

    renderContextMenu() {
      // return a single element, or nothing to use default browser behavior
      return (
        <Menu>
          <MenuItem onClick={this.handleSave} text="Save" />
          <MenuItem onClick={this.handleDelete} text="Delete" />
        </Menu>
      );
    }

    onContextMenuClose() {
      // Optional method called once the context menu is closed.
    }
  }
);
@TheDiamondDoge
Copy link

@Svenito Try to use ContextMenu.show() from "Imperative usage" section.

Works for me.

@Svenito
Copy link
Author

Svenito commented Feb 4, 2020

Thanks, that is what I ended up doing. I raised the issue as the above is expected to work according to the docs.

@maclockard
Copy link
Contributor

maclockard commented May 4, 2020

@Svenito This is most likely this issue: #3604

This is a solution: #3604 (comment)

if you are unable to do that, then this could also work: pmclachlan/blink-mind@79511a5

@natejcho
Copy link

natejcho commented Jul 16, 2020

@Svenito This is most likely this issue: #3604

This is a solution: #3604 (comment)

if you are unable to do that, then this could also work: pmclachlan/blink-mind@79511a5

Thanks!

The first is not possible if using CRA facebook/create-react-app#8139

Second is more applicable for my use case, and can be used for HOC method as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants