Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-state-with-callback

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-state-with-callback - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

2

lib/index.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports["use-state-with-callback"]=e(require("react")):t["use-state-with-callback"]=e(t.react)}(window,function(t){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var u=e[n]={i:n,l:!1,exports:{}};return t[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var u in t)r.d(n,u,function(e){return t[e]}.bind(null,u));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(e,r){e.exports=t},function(t,e,r){"use strict";r.r(e),r.d(e,"useStateWithCallbackInstant",function(){return o}),r.d(e,"useStateWithCallbackLazy",function(){return c});var n=r(0);function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,u=!1,o=void 0;try{for(var c,a=t[Symbol.iterator]();!(n=(c=a.next()).done)&&(r.push(c.value),!e||r.length!==e);n=!0);}catch(t){u=!0,o=t}finally{try{n||null==a.return||a.return()}finally{if(u)throw o}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var o=function(t,e){var r=u(n.useState(t),2),o=r[0],c=r[1];return n.useLayoutEffect(function(){return e(o)},[e,o]),[o,c]},c=function(t){var e=n.useRef(null),r=u(n.useState(t),2),o=r[0],c=r[1];n.useEffect(function(){e.current&&(e.current(o),e.current=null)},[o]);var a=n.useCallback(function(t,r){return e.current=r,c(t)},[]);return[o,a]};e.default=function(t,e){var r=u(n.useState(t),2),o=r[0],c=r[1];return n.useEffect(function(){return e(o)},[e,o]),[o,c]}}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports["use-state-with-callback"]=t(require("react")):e["use-state-with-callback"]=t(e.react)}(window,function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)r.d(n,u,function(t){return e[t]}.bind(null,u));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(t,r){t.exports=e},function(e,t,r){"use strict";r.r(t),r.d(t,"useStateWithCallbackInstant",function(){return o}),r.d(t,"useStateWithCallbackLazy",function(){return c});var n=r(0);function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=[],n=!0,u=!1,o=void 0;try{for(var c,f=e[Symbol.iterator]();!(n=(c=f.next()).done)&&(r.push(c.value),!t||r.length!==t);n=!0);}catch(e){u=!0,o=e}finally{try{n||null==f.return||f.return()}finally{if(u)throw o}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var o=function(e,t){var r=u(n.useState(e),2),o=r[0],c=r[1],f=n.useRef(!1);return n.useLayoutEffect(function(){f.current?t(o):f.current=!0},[o,t]),[o,c]},c=function(e){var t=n.useRef(null),r=u(n.useState(e),2),o=r[0],c=r[1];n.useEffect(function(){t.current&&(t.current(o),t.current=null)},[o]);var f=n.useCallback(function(e,r){return t.current=r,c(e)},[]);return[o,f]};t.default=function(e,t){var r=u(n.useState(e),2),o=r[0],c=r[1],f=n.useRef(!1);return n.useEffect(function(){f.current?t(o):f.current=!0},[o,t]),[o,c]}}])});
{
"name": "use-state-with-callback",
"version": "3.0.0",
"version": "3.0.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

# useStateWithCallback React Hook
[![Build Status](https://travis-ci.org/the-road-to-learn-react/use-state-with-callback.svg?branch=master)](https://travis-ci.org/the-road-to-learn-react/use-state-with-callback) [![Slack](https://slack-the-road-to-learn-react.wieruch.com/badge.svg)](https://slack-the-road-to-learn-react.wieruch.com/) [![Greenkeeper badge](https://badges.greenkeeper.io/the-road-to-learn-react/use-state-with-callback.svg)](https://greenkeeper.io/) ![NPM](https://img.shields.io/npm/l/use-state-with-callback.svg)
[![Build Status](https://travis-ci.org/the-road-to-learn-react/use-state-with-callback.svg?branch=master)](https://travis-ci.org/the-road-to-learn-react/use-state-with-callback) [![Greenkeeper badge](https://badges.greenkeeper.io/the-road-to-learn-react/use-state-with-callback.svg)](https://greenkeeper.io/) ![NPM](https://img.shields.io/npm/l/use-state-with-callback.svg)

@@ -16,3 +16,3 @@ Custom hook to include a callback function for useState which was previously available for setState in class components. [Read more about it here.](https://www.robinwieruch.de/react-usestate-callback/)

```jsx
import React from 'react';
import * as React from 'react';

@@ -25,12 +25,20 @@ import useStateWithCallback 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] = useStateWithCallback(0, currentCount => {
console.log('render, then callback.');
console.log('otherwise use useStateWithCallbackInstant()');
if (currentCount > 1) {
console.log('Threshold of over 1 reached.');
} else {
console.log('No threshold reached.');
}
});
// const [count, setCount] = useStateWithCallbackInstant(0, count => {
// if (count > 1) {
// console.log('render with instant callback.');
// const [count, setCount] = useStateWithCallbackInstant(0, currentCount => {
// console.log('render with instant callback.');
// if (currentCount > 1) {
// console.log('Threshold of over 1 reached.');
// } else {
// console.log('No threshold reached.');
// }

@@ -53,2 +61,4 @@ // });

};
export default App;
```

@@ -59,3 +69,3 @@

```jsx
import React from 'react';
import * as React from 'react';
import { useStateWithCallbackLazy } from 'use-state-with-callback';

@@ -62,0 +72,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc