react-hook-array
Advanced tools
+17
-9
| { | ||
| "name": "react-hook-array", | ||
| "version": "0.1.2", | ||
| "version": "0.1.3", | ||
| "author": { | ||
| "name": "Victor Moraes" | ||
| }, | ||
| "module": "useArray.js", | ||
| "unpkg": "useArray.js", | ||
| "main": "useArray.js", | ||
| "types": "useArray.d.ts", | ||
| "license": "GPL-3.0+", | ||
| "module": "index.js", | ||
| "unpkg": "index.js", | ||
| "main": "index.js", | ||
| "types": "index.d.ts", | ||
| "dependencies": { | ||
@@ -15,5 +16,12 @@ "react": "^18.2.0" | ||
| "files": [ | ||
| "useArray.js", | ||
| "useArray.d.ts" | ||
| ] | ||
| } | ||
| "index.js", | ||
| "index.d.ts" | ||
| ], | ||
| "scripts": { | ||
| "minify": "uglify-js --compress --output dist/index.js -- dist/index.js" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "^18.0.26", | ||
| "uglify-js": "^3.17.4" | ||
| } | ||
| } |
| import React from "react"; | ||
| export declare const useArray: <T>(initialValue: T[]) => readonly [T[], React.Dispatch<React.SetStateAction<T[]>>, (index: number, value: T) => void, (value: T) => void, () => T]; |
-31
| "use strict"; | ||
| var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
| if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
| if (ar || !(i in from)) { | ||
| if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
| ar[i] = from[i]; | ||
| } | ||
| } | ||
| return to.concat(ar || Array.prototype.slice.call(from)); | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| exports.__esModule = true; | ||
| exports.useArray = void 0; | ||
| var react_1 = __importDefault(require("react")); | ||
| var useArray = function (initialValue) { | ||
| var _a = react_1["default"].useState(initialValue), arr = _a[0], setArr = _a[1]; | ||
| var setArrByIndex = react_1["default"].useCallback(function (index, value) { | ||
| return setArr(function (oldArr) { return oldArr.map(function (x, idx) { return (idx === index ? value : x); }); }); | ||
| }, [setArr]); | ||
| var pushArr = react_1["default"].useCallback(function (value) { return setArr(function (oldArr) { return __spreadArray(__spreadArray([], oldArr, true), [value], false); }); }, [setArr]); | ||
| var popArr = react_1["default"].useCallback(function () { | ||
| // Will return undefined if array has length 0 | ||
| var last = arr[arr.length - 1]; | ||
| setArr(function (oldArr) { return oldArr.filter(function (x, idx) { return idx !== arr.length - 1; }); }); | ||
| return last; | ||
| }, [arr, setArr]); | ||
| return [arr, setArr, setArrByIndex, pushArr, popArr]; | ||
| }; | ||
| exports.useArray = useArray; |
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
Copyleft License
LicenseCopyleft license information was found.
Found 1 instance in 1 package
Non-permissive License
LicenseA license not known to be considered permissive was found.
Found 1 instance in 1 package
552
-73.74%2
Infinity%2
-50%2
Infinity%70
-30%0
-100%1
Infinity%