All Projects → the-road-to-learn-react → Use State With Callback

the-road-to-learn-react / Use State With Callback

Licence: mit
Custom hook to include a callback function for useState.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Use State With Callback

Thunks
A small and magical composer for all JavaScript asynchronous.
Stars: ✭ 523 (+255.78%)
Mutual labels:  callback
Duix
A State Manager focused on KISS and Pareto's Principle
Stars: ✭ 48 (-67.35%)
Mutual labels:  callback
Bach
Compose your async functions with elegance.
Stars: ✭ 117 (-20.41%)
Mutual labels:  callback
Jsftp
Light and complete FTP client implementation for Node.js
Stars: ✭ 766 (+421.09%)
Mutual labels:  callback
Zcoil
Elegant access to data
Stars: ✭ 20 (-86.39%)
Mutual labels:  callback
Gollback
Go asynchronous simple function utilities, for managing execution of closures and callbacks
Stars: ✭ 55 (-62.59%)
Mutual labels:  callback
Xxer
A blind XXE injection callback handler. Uses HTTP and FTP to extract information. Originally written in Ruby by ONsec-Lab.
Stars: ✭ 382 (+159.86%)
Mutual labels:  callback
Jquery Confirm
A multipurpose plugin for alert, confirm & dialog, with extended features.
Stars: ✭ 1,776 (+1108.16%)
Mutual labels:  callback
Keras telegram callback
Telegram-bot callback for your Keras model
Stars: ✭ 30 (-79.59%)
Mutual labels:  callback
Undopro
UndoPro is a command-based undo system integrated into Unity's default system. This allows devs to use actions for their undo/redo operations without forcing the user into a new undo-workflow!
Stars: ✭ 107 (-27.21%)
Mutual labels:  callback
Nem Apps Lib
Semantic Java API Library for NEM Platform
Stars: ✭ 16 (-89.12%)
Mutual labels:  callback
Taskmanager
A simple、 light(only two file)、fast 、powerful 、easy to use 、easy to extend 、 Android Library To Manager your AsyncTask/Thread/CallBack Jobqueue ! 一个超级简单,易用,轻量级,快速的异步任务管理器,类似于AsyncTask,但是比AsyncTask更好用,更易控制,从此不再写Thread ! ^_^
Stars: ✭ 25 (-82.99%)
Mutual labels:  callback
Network Idle Callback
Like requestIdleCallback, but for detecting network idle
Stars: ✭ 84 (-42.86%)
Mutual labels:  callback
Continuable
C++14 asynchronous allocation aware futures (supporting then, exception handling, coroutines and connections)
Stars: ✭ 655 (+345.58%)
Mutual labels:  callback
Clamscan
A robust ClamAV virus scanning library supporting scanning files, directories, and streams with local sockets, local/remote TCP, and local clamscan/clamdscan binaries (with failover).
Stars: ✭ 121 (-17.69%)
Mutual labels:  callback
Eventpp
Event Dispatcher and callback list for C++
Stars: ✭ 474 (+222.45%)
Mutual labels:  callback
Yii2 Rabbitmq
RabbitMQ Extension for Yii2
Stars: ✭ 52 (-64.63%)
Mutual labels:  callback
React Permissible
👮‍♂️Making the permission management for React components easier.
Stars: ✭ 145 (-1.36%)
Mutual labels:  callback
Poloniex Api Node
Poloniex API client for REST and WebSocket API
Stars: ✭ 138 (-6.12%)
Mutual labels:  callback
Object Observer
Object Observer functionality of JavaScript objects/arrays via native Proxy
Stars: ✭ 88 (-40.14%)
Mutual labels:  callback

useStateWithCallback React Hook

Build Status Slack Greenkeeper badge Coverage Status NPM

Custom hook to include a callback function for useState which was previously available for setState in class components. Read more about it here.

Installation

npm install use-state-with-callback

Usage

useStateWithCallback:

import React from 'react';

import useStateWithCallback from 'use-state-with-callback';

// Note: cannot be used on the server-side (e.g. Next.js)
// import { useStateWithCallbackInstant } from 'use-state-with-callback';

const App = () => {
  const [count, setCount] = useStateWithCallback(0, count => {
    if (count > 1) {
      console.log('render, then callback.');
      console.log('otherwise use useStateWithCallbackInstant()');
    }
  });

  // const [count, setCount] = useStateWithCallbackInstant(0, count => {
  //   if (count > 1) {
  //     console.log('render with instant callback.');
  //   }
  // });

  const handleClick = () => {
    setCount(count + 1);
  };

  return (
    <div>
      {count}

      <button type="button" onClick={handleClick}>
        Increase
      </button>
    </div>
  );
};

useStateWithCallbackLazy:

import React from 'react';
import { useStateWithCallbackLazy } from 'use-state-with-callback';

const App = () => {
  const [count, setCount] = useStateWithCallbackLazy(0);

  const handleClick = () => {
    setCount(count + 1, (currentCount) => {
      if (currentCount > 1) {
        console.log('Threshold of over 1 reached.');
      } else {
        console.log('No threshold reached.');
      }
    });
  };

  return (
    <div>
      <p>{count}</p>

      <button type="button" onClick={handleClick}>
        Increase
      </button>
    </div>
  );
};

export default App;

Contribute

  • git clone [email protected]:the-road-to-learn-react/use-state-with-callback.git
  • cd use-state-with-callback
  • npm install
  • npm run test

More

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].