Home > front end >  How to pass OnClick function to React antd Icon React Js
How to pass OnClick function to React antd Icon React Js

Time:10-24

To expand the visual, I need to pass the Onclick function to antd Expand icon(shown below).

enter image description here

const showModal = () => {
    setIsModalOpen(true);
};

const handleOk = () => {
    setIsModalOpen(false);
};

const handleCancel = () => {
    setIsModalOpen(false);
};

This is how i passed it to normal button currently.

        <div className="expandButton">
            <button
                type="button"
                className="fullScreenButton"
                onClick={showModal}
            >
                Click
            </button>
        </div>

Instead of this way can i pass the onclick function directly to react antd icon?

Current antd icon.

                    <div>
    
                        <ExpandAltOutlined style={{ fontSize: "150%" }} />
                    </div>

CodePudding user response:

Simply add an onClick event

<ExpandAltOutlined style={{ fontSize: "150%" }} onClick={()=>console.log('hj')} />
  • Related