[英]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.