버튼의 id를 구별하려고 원래는 매개변수로 구분하여 익명함수를 썼으나 익명함수를 쓰는 부분은 지양하라는 얘기에 써보게 된 부분이 이 getAttributedata-set이 있다. 요 2개를 살펴보려고 한다.

getAttribute

const onModalOpen = (e: React.MouseEvent<HTMLButtonElement>) => {
    const modalName = e.currentTarget.getAttribute('data-id');

    if (modalName === 'voucher') {
      setVoucherHistoryModalOpen(true);
    }
  };
<button data-id="voucher" onClick={onModalOpen} type="button">
   Voucher’s History
</button>

data-set

const onModalOpen = (e: React.MouseEvent<HTMLButtonElement>) => {
    const modalName = e.currentTarget.dataset.id;

    if (modalName === 'voucher') {
      setVoucherHistoryModalOpen(true);
    }
  };
<button data-id="voucher" onClick={onModalOpen} type="button">
   Voucher’s History
</button>

차이

둘의 차이가 궁금해서 찾아본 stackoverflow에서는