react-usehandlestate
Version:
A modified useState hook which exposes the commonly implmented handleChange function which can be used to modify state. handleChange supports modifying properties of objects stored in state including nested objects and their properties.
2 lines • 950 B
JavaScript
var T=Object.defineProperty;var h=Object.getOwnPropertySymbols;var d=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var u=(t,n,e)=>n in t?T(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,i=(t,n)=>{for(var e in n||(n={}))d.call(n,e)&&u(t,e,n[e]);if(h)for(var e of h(n))y.call(n,e)&&u(t,e,n[e]);return t};import{useState as g}from"react";function r(t,n,e){let s=n.split("."),l=i({},t),o=l;for(let a=0;a<s.length-1;a++){let P=s[a];o[P]=i({},o[P]),o=o[P]}return o[s[s.length-1]]=e,l}function S(t,n){return n===""?t:n.split(".").reduce((e,s)=>e==null?void 0:e[s],t)}function V(t){let[n,e]=g(t);function s(l,o){o===void 0?e(l):typeof o!="function"?(console.log("pram2 no function"),e(a=>r(a,l,o))):(console.log("param2 function"),e(a=>{let P=S(a,l);console.log("prevAtPath: ",P);let f=o(P);return console.log("nextAtPath: ",f),r(a,l,f)}))}return[n,s]}export{V as useHandleState};
//# sourceMappingURL=index.mjs.map