简体   繁体   English

第 93:6 行:React Hook useEffect 缺少依赖项:'estado'。 要么包含它,要么移除依赖数组 react-hooks/exhaustive-deps

[英]Line 93:6: React Hook useEffect has a missing dependency: 'estado'. Either include it or remove the dependency array react-hooks/exhaustive-deps

Can someone help me please?有人能帮助我吗?

I have the following problem!!我有以下问题!!

Line 93:6: React Hook useEffect has a missing dependency: 'estado'.第 93:6 行:React Hook useEffect 缺少依赖项:'estado'。 Either include it or remove the dependency array react-hooks/exhaustive-deps要么包含它,要么移除依赖数组 react-hooks/exhaustive-deps

  const [nome, setNome] = useState("");
  const [sobreNome, setSobreNome] = useState("");
  const [email, setEmail] = useState("");
  const [dataNascimento, setDataNascimento] = useState("");
  const [phone, setPhone] = useState("");
  const [estado, setEstado] = useState();
  const [cidade, setCidade] = useState();   
  const [lojas, setLojas] = useState();
  const [valueEstado, setValueEstado] = useState([]);
  const [valueUnidade, setValueUnidade] = useState([]);
  const navigate = useNavigate();

  useEffect(() => {
    let arr = [];
    unidades.map((item) => {
      if (estado === item.UF) {
        arr.push(item.Cidade);
      }
      return true
    });
    
    setValueEstado(arr);
  }, [estado]);

  useEffect(() => {
    let arr = [];
    unidades.map((item) => {
      if (cidade === item.Cidade && estado === item.UF) {
        arr.push({ Loja: item.Loja, CodigoFilial: item.CodigoFilial });
      }
      return true
    });
    setValueUnidade(arr);
  }, [cidade]);

Your second useEffect accesses the state variable "estado" but you don't list it in the dependency array (the second argument of useEffect).您的第二个 useEffect 访问 state 变量“estado”,但您没有在依赖数组中列出它(useEffect 的第二个参数)。 Note, this will cause your second useEffect to rerun anytime "estado" changes.请注意,这将导致您的第二个 useEffect 在任何“estado”更改时重新运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Hook useEffect 缺少依赖项:'fetchProfile'。 包括它或删除依赖数组 react-hooks/exhaustive-deps - React Hook useEffect has a missing dependency: 'fetchProfile'. Either include it or remove the dependency array react-hooks/exhaustive-deps React Hook useEffect 缺少依赖项:'formValues'。 包括它或删除依赖数组 react-hooks/exhaustive-deps - React Hook useEffect has a missing dependency: 'formValues'. Either include it or remove the dependency array react-hooks/exhaustive-deps React Hook useEffect 缺少依赖项:包含它或删除依赖项数组 react-hooks/exhaustive-deps - React Hook useEffect has a missing dependency: Either include it or remove the dependency array react-hooks/exhaustive-deps React Hook useEffect 缺少依赖项:'loading'。 包括它或删除依赖数组 react-hooks/exhaustive-deps - React Hook useEffect has a missing dependency: 'loading'. Either include it or remove the dependency array react-hooks/exhaustive-deps React Hook useEffect 缺少依赖项:'dispatch'。 包括它或删除依赖数组 react-hooks/exhaustive-deps - React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array react-hooks/exhaustive-deps React Hook useEffect 缺少依赖项要么包含它,要么删除依赖项数组 react-hooks/exhaustive-deps - React Hook useEffect has a missing dependency Either include it or remove the dependency array react-hooks/exhaustive-deps React Hook useEffect 缺少依赖项:'user.id'。 包括它或删除依赖数组 react-hooks/exhaustive-deps - React Hook useEffect has a missing dependency: 'user.id'. Either include it or remove the dependency array react-hooks/exhaustive-deps React Hook useEffect 缺少依赖项。 要么包含它,要么移除依赖数组 react-hooks/exhaustive-deps - React Hook useEffect has a missing dependency. Either include it or remove the dependency array react-hooks/exhaustive-deps React Hook useEffect 缺少依赖项:xxx。 包括它们或删除依赖数组 react-hooks/exhaustive-deps - React Hook useEffect has missing dependencies: xxx. Either include them or remove the dependency array react-hooks/exhaustive-deps React Hook useEffect 缺少依赖项:“roomID”和“sotreId”。 要么包含它们,要么删除依赖数组 react-hooks/exhaustive-deps - React Hook useEffect has missing dependencies: 'roomID 'and 'sotreId'. Either include them or remove the dependency array react-hooks/exhaustive-deps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM