npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-blockpress-hook

v1.0.4

Published

A react hook to help you take care of click loops by users and avoid conflicts in the backend.

Downloads

10

Readme

useBlockPress (react-hook)

A react hook to help you take care of clicks loops by users and avoid conflicts in the backend with queries. 😍😆😎 Remembering that if you want to read the article on Medium, here is the link: https://medium.com/@hubertryanofficial

$ yarn add react-blockpress-hook

or

$ npm install react-blockpress-hook --save

Quick Start

useBlockPress library was created to avoid a lot a clicks by bad users and take action on that user by identifying multiple clicks on a certain functionality.

As we use react's own hooks, we recommend using the react version from 16.8 onwards, thus making it possible to use the useEffect and useState hooks.

How to apply

One of the examples is avoid bad users make a lot of queries trying to bug the app engine or something like that, that's why the i developed this library hook. The first of all we need to specific two parameters of hook: onPress and onBlockPress. Below is saying more how we can use with examples!

...

import useBlockPress from "react-blockpress-hook";

const UseBlockButton = () => {
  const blockButtonClick = useBlockPress({
    onPress: onClick,
    onBlockButton: blockButtonListener,
  });

  function onClick() {
    console.log('Hello');
  }

  function blockButtonListener() {
    console.log('User onPress function blocked for some time.');
  }

  return (
    <View
      style={{
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
      }}>
      <TouchableOpacity onPress={blockButtonClick}>
        <View>
          <Text>Clique aqui</Text>
        </View>
      </TouchableOpacity>
    </View>
  );
};

In this example I'm not specifying how long the user will be blocked after trying to bypass some function. I'm not specifying how long the user will be blocked after trying to bypass some function. In this hook I thought a lot about how we are going to control this or how we are going to take some action after the user tries to repeat it several times. So we have two more parameters that will help us with this, which are: maximumClick and seconds.

...

//

const blockButtonClick = useBlockButton({
    onPress: onClick,
    onBlockButton: blockButtonListener,
    maximumClicks: 10,
    seconds: 5000
  });

The third parameter tells us with how many clicks we will say that the user is cheating and we will have to take action so that if it is hit, the blockButtonListener function will be called. The fourth parameter tells us how long the user will be blocked after circumventing the maximum number of attempts or repetitions in a specific component that is executing this function.

The first parameter

Important: Obviously the first parameter will tell us which function will be called by the component, and then to pass the function that returns us from the hook to the component..

Below we have a spreadsheet that will help us a little more as we define these parameters.

| Parameters | Type | Description | Default | | ------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------- | | onPress | Function | The function that should actually be called by the component, call a query or whatever. | any | | blockListener | Function | This function will be called whenever the user is blocked or reaches the limit. So you can better handle what to do with that user. | any | | maximumClicks | function | Maximum clicks that we will define what is already a scam | 10 | | seconds | function | How long in milliseconds (ms) the user will be blocked after reaching the click limit in maximumClicks. | 5000 |

You got it! 👍😁

I hope I helped at least a little you developers. Thank you very much, I hope I have helped the great React community. ❤🙌