react-mash

Button that can trigger a different function when repeatedly clicked in quick succession.

Usage no npm install needed!

<script type="module">
  import reactMash from 'https://cdn.skypack.dev/react-mash';
</script>

README

react-mash

A button component that has the ability to trigger a seperate function when repeatedly clicked.

Demo: https://codesandbox.io/s/lucid-pine-giitu

NPM install:

npm install react-mash

Use

All props that you normally pass to a button tag can be used as normal.

props

  • onClick - Function you would like to call when the button is clicked.
  • onMash - Function you would like to call when the button is repeatedly clicked.
  • clicks - Number of clicks that should trigger onMash.
  • interval - Time in which the number of clicks should trigger onMash.
  • resetOnMash - Default true. When set to false, mashing the button passed the number of clicks specified will continue to call the onMash function.

Example Usage:

import React from "react";
import ButtonMash from "react-mash";

export default function App() {

  return (
    <div>
      <ButtonMash
        clicks={12}
        interval={2000}
        onClick={() => console.log("clicked")}
        onMash={() => console.log("mashed")}
      >
        The Button
      </ButtonMash>
    </div>
  );
}