MUI 경고 대화 상자를 호출하는 더 좋은 방법

설치



npm으로 mui-react-alert 설치

  npm i mui-react-alert


데모



https://codesandbox.io/s/funny-mestorf-k2dcph

사용법/예제



App.tsx

import { AlertDialog } from "mui-react-alert";

function App() {
  return (
    <div className="App">
      <AlertDialog />
    </div>
  );
}

export default App;



버튼.tsx

import { showAlertConfirmarion } from "mui-react-alert";

function Button() {
  return (
      <button
      onClick={() => {
          showAlertConfirmarion({
          title: "Use Google's location service?",
          cancelLabel: "DISAGREE",
          confirmLabel: "AGREE",
          subtitle:
            "Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.",
          onConfirmation: function (): void {
            alert("Say hello");
          },
        });
      }}
    >
      Show alert dialog
    </button>
  );
}

export default Button;

좋은 웹페이지 즐겨찾기