본문 바로가기

프로그램 강좌

[react.js]오른쪽 버튼 사용방법

오른쪽 버튼 클릭 이벤트 사용방법

onContextMenu를 사용하면 됩니다.

App.js

import React, { Component } from 'react';

class App extends Component {
  handleLeftClick = () => {
    alert('Left Click');
  };
  handleRightClick = e => {
    e.preventDefault();
    alert('Right Click');
  };

  render() {
    const { handleLeftClick, handleRightClick } = this;
    return (
      <div>
        <button onClick={handleLeftClick} onContextMenu={handleRightClick}>
          right test
        </button>
      </div>
    );
  }
}

export default App;

오른쪽 버튼 눌렀을때도 이벤트가 잘 발생하네요.


728x90