@airma/react-hooks
Advanced tools
Comparing version 15.1.0 to 18.2.0
@@ -1,1 +0,1 @@ | ||
!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["@airma/react-hooks"]=t(require("react")):e["@airma/react-hooks"]=t(e.react)}(self,(function(e){return function(){"use strict";var t={156:function(t){t.exports=e}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var u=r[e]={exports:{}};return t[e](u,u.exports,n),u.exports}n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return function(){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}n.r(o),n.d(o,{useMount:function(){return c},usePersistFn:function(){return f},useUnmount:function(){return a},useUpdate:function(){return i}});var t=n(156);function r(t){return t&&"object"===e(t)}function u(){}function f(e){var r=(0,t.useRef)(e);r.current=e;var n=(0,t.useRef)((function(){return r.current.apply(r,arguments)}));return n.current}function c(e){var r=(0,t.useRef)(!1);(0,t.useEffect)((function(){var t=r.current;if(r.current=!0,t)return u;var n=e();return"function"==typeof n?n:u}),[])}function i(e,n){var o=(0,t.useRef)(void 0);(0,t.useEffect)((function(){var t=o.current;if(o.current={deps:n||[]},!t)return u;var f=t.deps;if(function(e,t){if(Object.is(e,t))return!0;if(!r(e)||!r(t))return!1;var n=Object.keys(e),o=Object.keys(t);if(n.length!==o.length)return!1;var u=e,f=t;return!n.some((function(e){return!Object.prototype.hasOwnProperty.call(f,e)}))&&!o.some((function(e){var t=f[e],r=u[e];return!Object.is(t,r)}))}(f,n||[]))return u;var c=e(f);return"function"==typeof c?c:u}),n)}function a(e){var r=(0,t.useRef)(!1);(0,t.useEffect)((function(){return r.current=!0,function(){var t=r.current;r.current=!1,t&&e()}}),[])}}(),o}()})); | ||
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("@airma/react-state"),require("@airma/react-effect"),require("react"),require("@airma/react-hooks-core")):"function"==typeof define&&define.amd?define(["@airma/react-state","@airma/react-effect","react","@airma/react-hooks-core"],r):"object"==typeof exports?exports["@airma/react-hooks"]=r(require("@airma/react-state"),require("@airma/react-effect"),require("react"),require("@airma/react-hooks-core")):e["@airma/react-hooks"]=r(e["@airma/react-state"],e["@airma/react-effect"],e.react,e["@airma/react-hooks-core"])}(self,(function(e,r,t,n){return function(){"use strict";var o={772:function(e){e.exports=r},309:function(e){e.exports=n},400:function(r){r.exports=e},156:function(e){e.exports=t},726:function(e,r,t){function n(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)t=u[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(n=0;n<u.length;n++)t=u[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}t.d(r,{Z:function(){return n}})},763:function(e,r,t){function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function o(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,u=[],i=!0,a=!1;try{for(t=t.call(e);!(i=(n=t.next()).done)&&(u.push(n.value),!r||u.length!==r);i=!0);}catch(e){a=!0,o=e}finally{try{i||null==t.return||t.return()}finally{if(a)throw o}}return u}}(e,r)||function(e,r){if(e){if("string"==typeof e)return n(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(e,r):void 0}}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}t.d(r,{Z:function(){return o}})}},u={};function i(e){var r=u[e];if(void 0!==r)return r.exports;var t=u[e]={exports:{}};return o[e](t,t.exports,i),t.exports}i.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(r,{a:r}),r},i.d=function(e,r){for(var t in r)i.o(r,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},i.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return function(){i.r(a),i.d(a,{ConfigProvider:function(){return l},Provider:function(){return t.StoreProvider},Strategy:function(){return n.Strategy},createKey:function(){return t.createKey},createSessionKey:function(){return n.createSessionKey},provide:function(){return t.provide},useControlledModel:function(){return t.useControlledModel},useIsFetching:function(){return n.useIsFetching},useLoadedSession:function(){return n.useLoadedSession},useModel:function(){return t.useModel},useMutation:function(){return n.useMutation},useQuery:function(){return n.useQuery},useRealtimeInstance:function(){return t.useRealtimeInstance},useResponse:function(){return n.useResponse},useSelector:function(){return t.useSelector},useSession:function(){return n.useSession}});var e=i(726),r=i(763),t=i(400),n=i(772),o=i(156),u=i(309),c={};for(var s in u)["default","createKey","useModel","useControlledModel","useRealtimeInstance","useSelector","createSessionKey","Strategy","useQuery","useMutation","useSession","useLoadedSession","useResponse","useIsFetching","provide","Provider","ConfigProvider"].indexOf(s)<0&&(c[s]=function(e){return u[e]}.bind(0,s));i.d(a,c);var f=["batchUpdate"],l=function(u){var i=u.value,a=u.children,c=(0,o.useMemo)((function(){return[{batchUpdate:i.batchUpdate},(0,e.Z)(i,f)]}),[]),s=(0,r.Z)(c,2),l=s[0],d=s[1];return(0,o.createElement)(t.ConfigProvider,{value:l},(0,o.createElement)(n.ConfigProvider,{value:d},a))}}(),a}()})); |
@@ -1,12 +0,45 @@ | ||
export declare function usePersistFn<T extends (...args: any[]) => any>( | ||
callback: T | ||
): T; | ||
import { FC, FunctionComponent, NamedExoticComponent, ReactNode } from 'react'; | ||
import { | ||
GlobalConfig as StateGlobalConfig, | ||
ModelKeys | ||
} from '@airma/react-state'; | ||
import { GlobalConfig as EffectGlobalConfig } from '@airma/react-effect'; | ||
export declare function useMount(callback: () => (() => void) | void): void; | ||
export declare type GlobalConfig = StateGlobalConfig & EffectGlobalConfig; | ||
export declare function useUpdate<T extends any[]>( | ||
callback: (prevDeps: undefined | T) => (() => void) | void, | ||
deps?: T | ||
): void; | ||
export * from '@airma/react-hooks-core'; | ||
export declare function useUnmount(destroy: () => void): void; | ||
export { | ||
createKey, | ||
useModel, | ||
useControlledModel, | ||
useRealtimeInstance, | ||
useSelector | ||
} from '@airma/react-state'; | ||
export { | ||
createSessionKey, | ||
Strategy, | ||
useQuery, | ||
useMutation, | ||
useSession, | ||
useLoadedSession, | ||
useResponse, | ||
useIsFetching | ||
} from '@airma/react-effect'; | ||
export declare function provide( | ||
keys: ModelKeys | ||
): <P extends Record<string, any>>( | ||
component: FunctionComponent<P> | NamedExoticComponent<P> | ||
) => typeof component; | ||
export declare const Provider: FC<{ | ||
value: ModelKeys; | ||
children?: ReactNode; | ||
}>; | ||
export declare const ConfigProvider: FC<{ | ||
value: GlobalConfig; | ||
children?: ReactNode; | ||
}>; |
{ | ||
"private": false, | ||
"name": "@airma/react-hooks", | ||
"version": "15.1.0", | ||
"version": "18.2.0", | ||
"description": "This is a common react hook package", | ||
@@ -28,3 +28,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"react": ">=16.8.0" | ||
"react": ">=16.8.0", | ||
"@airma/react-hooks-core": "^18.0.0", | ||
"@airma/react-state": "^18.2.0", | ||
"@airma/react-effect": "^18.2.0" | ||
}, | ||
@@ -31,0 +34,0 @@ "devDependencies": { |
@@ -13,76 +13,8 @@ [![npm][npm-image]][npm-url] | ||
It is a simple tool for providing some simple and useful react hooks for `@airma/react-*` tools. You can use it too. | ||
Now, it is a set package abount `@airma/react-*` tools. You can use it to replace `@airma/react-*` packages. | ||
## API | ||
## Document | ||
### usePersistFn | ||
* [中文](https://filefoxper.github.io/airma/#/zh/react-hooks/index) | ||
* [En](https://filefoxper.github.io/airma/#/react-hooks/index) | ||
```ts | ||
export declare function usePersistFn<T extends (...args: any[]) => any>( | ||
callback: T | ||
): T; | ||
``` | ||
This hook is created for replacing `useCallback`, if you want to create a persist callback. | ||
```ts | ||
import {memo} from 'react'; | ||
import {usePersistFn} from '@airma/react-hooks'; | ||
const App = memo((props: {onChange: (value:string)=>void})=>{ | ||
return ...; | ||
}); | ||
const Layout = ()=>{ | ||
const call = usePersistFn((v: string)=>{}); | ||
return <App onChange={call}/> | ||
} | ||
``` | ||
### useMount | ||
```ts | ||
export declare function useMount(callback: () => (() => void) | void): void; | ||
``` | ||
This hook is created for listen the mount effect of functional component. | ||
### useUpdate | ||
```ts | ||
export declare function useUpdate<T extends any[]>( | ||
callback: (prevDeps: undefined | T) => (() => void) | void, | ||
deps?: T | ||
): void; | ||
``` | ||
This hook is created for listen the update effect of functional component. | ||
```ts | ||
import {memo, useState} from 'react'; | ||
import {useUpdate} from '@airma/react-hooks'; | ||
const App = memo((props: {value:number})=>{ | ||
const [count, setCount] = useState(props.value); | ||
useUpdate((prev)=>{ | ||
if(!prev){ | ||
return; | ||
} | ||
const [prevValue] = prev; | ||
console.log(prevValue) | ||
}, [props.value]); | ||
return ...; | ||
}); | ||
``` | ||
### useUnmount | ||
```ts | ||
export declare function useUnmount(destroy: () => void): void; | ||
``` | ||
This hook is created for listen the unmount effect of functional component. |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
7591
38
0
4
20
+ Added@airma/react-effect@^18.2.0
+ Added@airma/react-state@^18.2.0
+ Added@airma/react-effect@18.5.11(transitive)
+ Added@airma/react-hooks-core@18.3.0(transitive)
+ Added@airma/react-state@18.5.7(transitive)