diff --git a/src/components/ModalPluginItem.js b/src/components/ModalPluginItem.js index 4e6ebbde..10f49764 100644 --- a/src/components/ModalPluginItem.js +++ b/src/components/ModalPluginItem.js @@ -4,30 +4,26 @@ * License: MIT */ -import React, { Component } from "react"; +import React, { useContext, useRef } from "react"; import { ActionsContext } from "./ActionsProvider"; import { PLUGINS_MODAL_ADD_PLUGIN } from "../constants"; -export default class ModalPluginItem extends Component { - static contextType = ActionsContext; +const ModalPluginItem = props => { + const buttonEl = useRef(null); + const actionsContext = useContext(ActionsContext); - constructor(props) { - super(props); - this.handleClick = this.handleClick.bind(this); - this.closeModal = this.closeModal.bind(this); - this.renderButton = this.renderButton.bind(this); - } + const handleClick = e => { + if (buttonEl.current) { + buttonEl.current.onClick(e); + } + }; - handleClick(e) { - this.buttonEl.onClick(e); - } + const closeModal = () => { + props.toggleModalVisibility(); + }; - closeModal() { - this.props.toggleModalVisibility(); - } - - renderButton(item) { + const renderButton = item => { const Button = item.buttonComponent; return ( @@ -35,37 +31,32 @@ export default class ModalPluginItem extends Component { key={item.type} className="megadraft-modal__item" onClick={() => { - this.context.onAction({ + actionsContext.onAction({ type: PLUGINS_MODAL_ADD_PLUGIN, pluginName: item.title }); - this.closeModal(); + closeModal(); }} >