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

use-hook-kits

v0.0.30

Published

![npm](https://img.shields.io/npm/dt/use-hook-kits.svg) ![npm](https://img.shields.io/npm/v/use-hook-kits.svg) ![NpmLicense](https://img.shields.io/npm/l/use-hook-kits.svg)

Downloads

371

Readme

Use Hook Kits

npm npm NpmLicense

Use Hook Kits Read about Hooks feature.

Installation

Note: React 16.8+ is required for Hooks.

With npm

npm i use-hook-kits

Or with yarn

yarn add use-hook-kits

Usage

useState

import React from "react";
import { useState } from "use-hook-kits";

function App({ object, array }) {
  const [state, setState] = useState(0);

  const onCount = () => setState(state++, (nextState) => {// callback after change state})

  const onCountPrevState = () => setState(prev => prev++, (nextState) => {// callback after change state})

  return <View/>;
}

export default deepMemo(App);

deepMemo

import React from "react";
import { deepMemo } from "use-hook-kits";

function App({ object, array }) {
  return <View/>;
}
export default deepMemo(App);

useMount

import React from "react";
import { useMount } from "use-hook-kits";

function App({ object, array }) {
  useMount(() => {
    // do something significant here
  });

  return <View/>;
}

useDidMount

import React from "react";
import { useDidMount } from "use-hook-kits";

function App({ object, array }) {
  useDidMount(() => {
    // do something significant here
  });

  return <View/>;
}

useDidUpdate

import React from "react";
import { useDidUpdate } from "use-hook-kits";

function App({ object, array }) {
  useDidUpdate(() => {
    // do something significant here
  }, [object, array]);

  return <View/>;
}

useDeepEffect

import React from "react";
import { useDeepEffect } from "use-hook-kits";

function App({ object, array }) {
  useDeepEffect(() => {
    // do something significant here
    return () => {
      // return to clean up that significant thing
    };
  }, [object, array]);

  return <View/>;
}

useDeepCallback

import React from "react";
import { useDeepCallback } from "use-hook-kits";

function App({ object, array }) {
  const callback = useDeepCallback(() => {
    // do something significant here
  }, [object, array]);

  return <View/>;
}

useDeepMemo

import React from "react";
import { useDeepMemo } from "use-hook-kits";

function App({ object, array }) {
  const memoized = useDeepMemo(() => {
    // do something significant here
  }, [object, array]);

  return <View/>;
}

useInterval

import React from "react";
import { useInterval } from "use-hook-kits";

function App({ object, array }) {
   useInterval(() => {
    // do something significant here
  }, 1000, true);

  return <View/>;
}

usePrevious

import React from "react";
import { usePrevious } from "use-hook-kits";

function App() {
  // State value and setter for our example
  const [count, setCount] = React.useState(0);
  
  // Get the previous value (was passed into hook on last render)
  const prevCount = usePrevious(count);
  
  return <View/>;
}

useDebounce

import React from "react";
import { useDebounce } from "use-hook-kits";

function App() {
  // State value and setter for our example
  const [text, setText] = useState('Hello');
  //Debounce value
  const [value] = useDebounce(text, 1000);
  
  return <View/>;
}

useDebounceCallback

import React from "react";
import { useDebounceCallback } from "use-hook-kits";

function App({ object, array }) {
 const [value, setValue] = useState(defaultValue);
  // Debounce callback
  const [debouncedCallback] = useDebounceCallback(
    // function
    (value) => {
      setValue(value);
    },
    // delay in ms
    1000
  );

  return <TextInput defaultValue={defaultValue} onChangeText={(value) => debouncedCallback(value)} />;
}

useThrottleCallback

import React from "react";
import { useThrottleCallback } from "use-hook-kits";

function App({ object, array }) {
 const [value, setValue] = useState(defaultValue);
  // Debounce callback
  const [throttleCallback] = useThrottleCallback(
    // function
    (value) => {
      setValue(value);
    },
    // delay in ms
    1000
  );

  return <TextInput defaultValue={defaultValue} onChangeText={(value) => throttleCallback(value)} />;
}

useFocusEffect

import React, {useCallback} from "react";
import { useFocusEffect } from "use-hook-kits";

function App({ navigation }) {
  
  useFocusEffect(() => {
    //Component will focus
  }, navigation);

  return <View/>;
}

useTimeoutPromise

import React from "react";
import { useTimeoutPromise } from "use-hook-kits";

const fetchApi = () => new Promise((resolve, reject) => {});

function App({ object, array }) {

useEffect(() => {
      const fetchData = () => useTimeoutPromise(10000,fetchApi());
      // fetchData will reject after 10s if no response
      fetchData();
  }, [])

  return <View/>;
}

useContext, useLogger

import React from "react";
import { StateProvider, useSelector, useDispatch, useLogger } from "use-hook-kits";

const stores = {
    count: 0
};

const reducer = (state, action) => {
    switch (action.type) {
    case 'SET_COUNT':
        return {
            ...state,
            count: action.payload
        };
    default:
        return state;
    }
};

export const setCountDown = ({ dispatch, payload }) => dispatch({ type: 'SET_COUNT', payload });

// Use in App
function App({ object, array }) {
  return (
    <StateProvider reducer={reducer} stores={stores} logger={process.env.NODE_ENV === 'development' ? useLogger : null}>
          <AppContext {...props} />
     </StateProvider>
    );
}

function AppContext({ object, array }) {
  const count = useSelector('count');

  const dispatch = useDispatch();

  const onChangeCount = () => setCountDown({dispatch, count++})

  return <Text>{count}</Text>
}