/** @license React v4.2.0 * eslint-plugin-react-hooks.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict';function ca(a,c){if(a){if("string"===typeof a)return da(a,c);var b=Object.prototype.toString.call(a).slice(8,-1);"Object"===b&&a.constructor&&(b=a.constructor.name);if("Map"===b||"Set"===b)return Array.from(a);if("Arguments"===b||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(b))return da(a,c)}}function da(a,c){if(null==c||c>a.length)c=a.length;for(var b=0,d=Array(c);b=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function(a){throw a;},f:c}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var e=!0,n=!1,h;return{s:function(){b=a[Symbol.iterator]()}, n:function(){var a=b.next();e=a.done;return a},e:function(a){n=!0;h=a},f:function(){try{e||null==b.return||b.return()}finally{if(n)throw h;}}}}function H(a){if("Identifier"===a.type)return/^use[A-Z0-9].*$/.test(a.name);if("MemberExpression"===a.type&&!a.computed&&H(a.property)){a=a.object;var c=/^[A-Z].*/;return"Identifier"===a.type&&c.test(a.name)}return!1}function ea(a){return"Identifier"===a.type?!/^[a-z]/.test(a.name):!1} function fa(a,c){return a.name===c||"MemberExpression"===a.type&&"React"===a.object.name&&a.property.name===c}function ha(a){return!!(a.parent&&a.parent.callee&&fa(a.parent.callee,"forwardRef"))}function ia(a){return!!(a.parent&&a.parent.callee&&fa(a.parent.callee,"memo"))}function ma(a){for(;a;){var c=na(a);if(c&&(ea(c)||H(c))||ha(a)||ia(a))return!0;a=a.parent}return!1} function na(a){if("FunctionDeclaration"===a.type||"FunctionExpression"===a.type&&a.id)return a.id;if("FunctionExpression"===a.type||"ArrowFunctionExpression"===a.type)return"VariableDeclarator"===a.parent.type&&a.parent.init===a?a.parent.id:"AssignmentExpression"===a.parent.type&&a.parent.right===a&&"="===a.parent.operator?a.parent.left:"Property"!==a.parent.type||a.parent.value!==a||a.parent.computed?"AssignmentPattern"!==a.parent.type||a.parent.right!==a||a.parent.computed?void 0:a.parent.left: a.parent.key} function I(a){function c(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}function b(a,b){b=b.split(".");b=C(b);var l;try{for(b.s();!(l=b.n()).done;){var d=l.value,e=a.children.get(d);e||(e=c(),a.children.set(d,e));a=e}}catch(F){b.e(F)}finally{b.f()}return a}function d(a,c,b){c=c.split(".");c=C(c);var d;try{for(c.s();!(d=c.n()).done;){var e=a.children.get(d.value);if(!e)break;b(e);a=e}}catch(F){c.e(F)}finally{c.f()}}function e(a,c,b,d){a.children.forEach(function(a,l){var f= d(l);a.isSatisfiedRecursively?a.isSubtreeUsed&&b.add(f):a.isUsed?c.add(f):e(a,c,b,function(a){return f+"."+a})})}var n=a.dependencies,h=a.declaredDependencies,x=a.stableDependencies,k=a.externalDependencies,D=a.isEffect,y=c();n.forEach(function(a,c){b(y,c).isUsed=!0;d(y,c,function(a){a.isSubtreeUsed=!0})});h.forEach(function(a){b(y,a.key).isSatisfiedRecursively=!0});x.forEach(function(a){b(y,a).isSatisfiedRecursively=!0});a=new Set;var g=new Set;e(y,a,g,function(a){return a});var f=[],u=new Set,q= new Set;h.forEach(function(a){a=a.key;g.has(a)?-1===f.indexOf(a)?f.push(a):q.add(a):!D||a.endsWith(".current")||k.has(a)?u.add(a):-1===f.indexOf(a)&&f.push(a)});a.forEach(function(a){f.push(a)});return{suggestedDependencies:f,unnecessaryDependencies:u,duplicateDependencies:q,missingDependencies:a}} function R(a){switch(a.type){case "ObjectExpression":return"object";case "ArrayExpression":return"array";case "ArrowFunctionExpression":case "FunctionExpression":return"function";case "ClassExpression":return"class";case "ConditionalExpression":if(null!=R(a.consequent)||null!=R(a.alternate))return"conditional";break;case "LogicalExpression":if(null!=R(a.left)||null!=R(a.right))return"logical expression";break;case "JSXFragment":return"JSX fragment";case "JSXElement":return"JSX element";case "AssignmentExpression":if(null!= R(a.right))return"assignment expression";break;case "NewExpression":return"object construction";case "Literal":if(a.value instanceof RegExp)return"regular expression";break;case "TypeCastExpression":return R(a.expression);case "TSAsExpression":return R(a.expression)}return null} function oa(a){var c=a.declaredDependenciesNode,b=a.componentScope,d=a.scope;return a.declaredDependencies.map(function(a){var c=a.key;a=b.variables.find(function(a){return a.name===c});if(null==a)return null;var d=a.defs[0];if(null==d)return null;if("Variable"===d.type&&"VariableDeclarator"===d.node.type&&"Identifier"===d.node.id.type&&null!=d.node.init){var e=R(d.node.init);if(null!=e)return[a,e]}return"FunctionName"===d.type&&"FunctionDeclaration"===d.node.type?[a,"function"]:"ClassName"===d.type&& "ClassDeclaration"===d.node.type?[a,"class"]:null}).filter(Boolean).map(function(a){var b=a[0];a=a[1];var e=b.defs[0];a:{for(var x=!1,k=0;k=c.range[1]}exports.configs={recommended:{plugins:["react-hooks"],rules:{"react-hooks/rules-of-hooks":"error","react-hooks/exhaustive-deps":"warn"}}}; exports.rules={"rules-of-hooks":{meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",category:"Possible Errors",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"}},create:function(a){var c=[],b=[];return{onCodePathSegmentStart:function(a){return b.push(a)},onCodePathSegmentEnd:function(){return b.pop()},onCodePathStart:function(){return c.push(new Map)},onCodePathEnd:function(b,e){function d(a,c){var f=d.cache,e=f.get(a.id);c=new Set(c);if(c.has(a.id)){f=[].concat(c); a=f.slice(f.indexOf(a.id)+1);a=C(a);var g;try{for(a.s();!(g=a.n()).done;)D.add(g.value)}catch(B){a.e(B)}finally{a.f()}return 0}c.add(a.id);if(void 0!==e)return e;if(b.thrownSegments.includes(a))e=0;else if(0===a.prevSegments.length)e=1;else{e=0;g=C(a.prevSegments);var E;try{for(g.s();!(E=g.n()).done;)e+=d(E.value,c)}catch(B){g.e(B)}finally{g.f()}}a.reachable&&0===e?f.delete(a.id):f.set(a.id,e);return e}function h(a,c){var d=h.cache,e=d.get(a.id);c=new Set(c);if(c.has(a.id)){d=Array.from(c);a=d.slice(d.indexOf(a.id)+ 1);a=C(a);var f;try{for(a.s();!(f=a.n()).done;)D.add(f.value)}catch(B){a.e(B)}finally{a.f()}return 0}c.add(a.id);if(void 0!==e)return e;if(b.thrownSegments.includes(a))e=0;else if(0===a.nextSegments.length)e=1;else{e=0;f=C(a.nextSegments);var g;try{for(f.s();!(g=f.n()).done;)e+=h(g.value,c)}catch(B){f.e(B)}finally{f.f()}}d.set(a.id,e);return e}function x(a){var c=x.cache,b=c.get(a.id);if(null===b)return Infinity;if(void 0!==b)return b;c.set(a.id,null);if(0===a.prevSegments.length)b=1;else{b=Infinity; var d=C(a.prevSegments),e;try{for(d.s();!(e=d.n()).done;){var f=x(e.value);f {\n async function fetchData() {\n // You can await here\n const response = await MyAPI.getData(someId);\n // ...\n }\n fetchData();\n}, [someId]); // Or [] if effect doesn't need props or state\n\nLearn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching"}); for(var z=h.acquire(d),F=new Set,r=null,A=z.upper;A;){F.add(A);if("function"===A.type)break;A=A.upper}if(A){r=A;var U=b(function(a){if(!Array.isArray(a.defs))return!1;var c=a.defs[0];if(null==c||"VariableDeclarator"!==c.node.type)return!1;var b=c.node.init;if(null==b)return!1;for(;"TSAsExpression"===b.type;)b=b.expression;var d=c.node.parent;if(null==d&&(X(r.block,c.node.id),d=c.node.parent,null==d))return!1;if("const"===d.kind&&"Literal"===b.type&&("string"===typeof b.value||"number"===typeof b.value|| null===b.value))return!0;if("CallExpression"!==b.type)return!1;b=b.callee;"MemberExpression"!==b.type||"React"!==b.object.name||null==b.property||b.computed||(b=b.property);if("Identifier"!==b.type)return!1;c=c.node.id;b=b.name;if("useRef"===b&&"Identifier"===c.type)return!0;if("useState"===b||"useReducer"===b){if("ArrayPattern"===c.type&&2===c.elements.length&&Array.isArray(a.identifiers)){if(c.elements[1]===a.identifiers[0]){if("useState"===b)for(a=a.references,b=0;b { return ","; })"]:["useCallback(",")"],d=c[1];return[a.insertTextBefore(b.node.init,c[0]),a.insertTextAfter(b.node.init,d)]}}]);c({node:b.node,message:m,suggest:h})});else{!l&&0 ...)' if you only need '"+w.missingDep+"' in the '"+(w.setter+"' call.");break;default:throw Error("Unknown case.");}}c({node:e, message:"React Hook "+a.getSource(u)+" has "+(n(G,"a","missing","include")||n(A,"an","unnecessary","exclude")||n(E,"a","duplicate","omit"))+p,suggest:[{desc:"Update the dependencies array to be: ["+S.map(g).join(", ")+"]",fix:function(a){return a.replaceText(e,"["+S.map(g).join(", ")+"]")}}]})}}else{var Q=null;v.forEach(function(a,b){Q||a.references.forEach(function(a){if(!Q&&x.has(a.identifier)){for(a=a.from;"function"!==a.type;)a=a.upper;a.block===d&&(Q=b)}})});if(Q){var ba=I({dependencies:v,declaredDependencies:[], stableDependencies:N,externalDependencies:new Set,isEffect:!0}).suggestedDependencies;c({node:u,message:"React Hook "+q+" contains a call to '"+Q+"'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass ["+ba.join(", ")+("] as a second argument to the "+q+" Hook."),suggest:[{desc:"Add dependencies array: ["+ba.join(", ")+"]",fix:function(a){return a.insertTextAfter(d,", ["+ba.join(", ")+"]")}}]})}}}}var e=a.options&&a.options[0]&&a.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops|| !1,n={additionalHooks:a.options&&a.options[0]&&a.options[0].additionalHooks?new RegExp(a.options[0].additionalHooks):void 0,enableDangerousAutofixThisMayCauseInfiniteLoops:e},h=a.getSourceCode().scopeManager,x=new WeakMap,k=new WeakSet,D=new WeakMap,y=new WeakMap;return{CallExpression:function(b){var e=ta(b.callee,n);if(-1!==e){var g=b.arguments[e],h=b.callee,l=sa(h).name,k=b.arguments[e+1];b=/Effect($|[^a-z])/g.test(l);if(k||b){switch(g.type){case "FunctionExpression":case "ArrowFunctionExpression":d(g, k,h,l,b);return;case "Identifier":if(!k||k.elements&&k.elements.some(function(a){return a&&"Identifier"===a.type&&a.name===g.name}))return;e=a.getScope().set.get(g.name);if(null==e||null==e.defs)return;e=e.defs[0];if(!e||!e.node)break;if("Variable"!==e.type&&"FunctionName"!==e.type)break;switch(e.node.type){case "FunctionDeclaration":d(e.node,k,h,l,b);return;case "VariableDeclarator":if(e=e.node.init)switch(e.type){case "ArrowFunctionExpression":case "FunctionExpression":d(e,k,h,l,b);return}}break; default:c({node:h,message:"React Hook "+l+" received a function whose dependencies are unknown. Pass an inline function instead."});return}c({node:h,message:"React Hook "+l+" has a missing dependency: '"+g.name+"'. Either include it or remove the dependency array.",suggest:[{desc:"Update the dependencies array to be: ["+g.name+"]",fix:function(a){return a.replaceText(k,"["+g.name+"]")}}]})}else"useMemo"!==l&&"useCallback"!==l||c({node:h,message:"React Hook "+l+" does nothing when called with only one argument. Did you forget to pass an array of dependencies?"})}}}}}};