react-hook-array
Advanced tools
Sorry, the diff of this file is not supported yet
+7
-1
| import React from "react"; | ||
| export declare const useArray: <T>(initialValue: T[]) => readonly [T[], React.Dispatch<React.SetStateAction<T[]>>, (index: number, update: React.SetStateAction<T>) => void, (value: T) => void, () => T | undefined]; | ||
| export declare const useArray: <T>(initialValue: T[]) => { | ||
| arr: T[]; | ||
| setArr: React.Dispatch<React.SetStateAction<T[]>>; | ||
| setArrByIndex: (index: number, update: React.SetStateAction<T>) => void; | ||
| pushArr: (value: T) => void; | ||
| popArr: () => T | undefined; | ||
| }; |
+1
-16
@@ -1,16 +0,1 @@ | ||
| import React from "react"; | ||
| const isFunction = (x) => typeof x === "function"; | ||
| const updateFn = (update, x) => isFunction(update) ? update(x) : update; | ||
| export const useArray = (initialValue) => { | ||
| const [arr, setArr] = React.useState(initialValue); | ||
| const setArrByIndex = React.useCallback((index, update) => { | ||
| setArr((old) => old.map((x, idx) => (idx === index ? updateFn(update, x) : x))); | ||
| }, [setArr]); | ||
| const pushArr = React.useCallback((value) => setArr((old) => [...old, value]), [setArr]); | ||
| const popArr = React.useCallback(() => { | ||
| const last = arr[arr.length - 1]; | ||
| setArr((old) => old.filter((x, idx) => idx !== arr.length - 1)); | ||
| return last; | ||
| }, [arr, setArr]); | ||
| return [arr, setArr, setArrByIndex, pushArr, popArr]; | ||
| }; | ||
| import React from"react";const isFunction=t=>"function"==typeof t,updateFn=(t,e)=>isFunction(t)?t(e):t;export const useArray=t=>{const[e,r]=React.useState(t),a=React.useCallback(((t,e)=>{r((r=>r.map(((r,a)=>a===t?updateFn(e,r):r))))}),[r]),n=React.useCallback((t=>r((e=>[...e,t]))),[r]),c=React.useCallback((()=>{const t=e[e.length-1];return r((t=>t.filter(((t,r)=>r!==e.length-1)))),t}),[e,r]);return{arr:e,setArr:r,setArrByIndex:a,pushArr:n,popArr:c}}; |
+4
-4
| { | ||
| "name": "react-hook-array", | ||
| "version": "0.1.7", | ||
| "version": "0.1.8", | ||
| "author": { | ||
@@ -19,8 +19,8 @@ "name": "Victor Moraes", | ||
| "scripts": { | ||
| "minify": "npx uglify-js --compress --output dist/index.js -- dist/index.js" | ||
| "minify": "npx terser --compress --mangle --output dist/index.js -- dist/index.js" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "^18.0.26", | ||
| "uglify-js": "^3.17.4" | ||
| "terser": "^5.16.3" | ||
| } | ||
| } | ||
| } |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
7475
369.54%5
25%8
-55.56%3
50%1
Infinity%