1.0.5 • Published 3 years ago

@gitgw/use-confirm v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@gitgw/use-confirm

React Hook to prompt a confirmation before executing a function.

Installation

npm

npm i @gitgw/use-confirm

yarn

yarn add @gitgw/use-confirm

Usage

import React from "react";
import useConfirm from "@gitgw/use-confirm";

function App() {
  const onConfirm = () => {
    console.log("onConfirm");
  }
  const onCancel = () => {
    console.log("onCancel");
  }

  const confirmAction = useConfirm("true or false?", onConfirm, onCancel);
  
  return (
    <div className="App">
      <button onClick={confirmAction}>confirmAction</button>;
    </div>
  );
}

Arguments

ArgumentTypeDescriptionRequired
messageStringMessage to show the user on the confirmation propmtyes
onConfirmFunctionFunction to be executed when the user confirmsyes
onCancelFunctionFunction to be executed when the user cancelsyes

Return

Return valueTypeDescriptionDefault value
FunctionFunctionFunction wrapped around the confirmation logicnull