简体   繁体   English

React Hook useEffect 缺少依赖项:“hideLoader”和“showLoader”。 包括它们或删除依赖数组

[英]React Hook useEffect has missing dependencies: 'hideLoader' and 'showLoader'. Either include them or remove the dependency array

how can i solve this error => React Hook useEffect has missing dependencies: 'hideLoader' and 'showLoader'.我该如何解决这个错误=> React Hook useEffect 缺少依赖项:“hideLoader”和“showLoader”。 Either include them or remove the dependency array react-hooks/exhaustive-deps要么包含它们,要么删除依赖数组 react-hooks/exhaustive-deps

if i'm using [showLoader, hideLoader] as dependencies then hideLoader is not working?如果我使用[showLoader, hideLoader]作为依赖项,那么 hideLoader 不起作用? how can i fix this... showLoader is always showing spinner even axios fetch data!我该如何解决这个问题... showLoader 总是显示微调器,即使 axios 获取数据!

FullPageLoader.js FullPageLoader.js

import React from "react";
import Spinner from './loader/spinner.gif

const FullPageLoader = () => {
    return (
        <div className="text-center">
            <img src={Spinner} className="fp-loader" alt="loading" style={{ marginTop: '8%' }} />
        </div>
    );
};

export default FullPageLoader;

useFullPageLoader.js使用FullPageLoader.js

import React, { useState } from "react";
import FullPageLoader from "../FullPageLoader";

const useFullPageLoader = () => {
    const [loading, setLoading] = useState(false);

    return [
        loading ? <FullPageLoader /> : null,
        () => setLoading(true), //Show loader
        () => setLoading(false) //Hide Loader
    ];
};

export default useFullPageLoader;

App.js应用程序.js

import useFullPageLoader from "../components/hook/useFullPageLoader";

const [loader, showLoader, hideLoader] = useFullPageLoader();

useEffect(() => {
    const fetchItems = async () => {
        try {
            showLoader();
            const res = await axios.get(`${process.env.REACT_APP_API_URL}/api/approved/`);
            setItems(res.data)
            hideLoader();
        }
        catch (err) {
            console.log(`😱 Axios request failed: ${err}`);
        }
    }
    fetchItems();
}, [hideLoader, showLoader]);

It's telling you what to do:它告诉你该怎么做:

const [loader, showLoader, hideLoader] = useFullPageLoader();

useEffect(() => {
    const fetchItems = async () => {
        try {
            showLoader();
            const res = await axios.get(`${process.env.REACT_APP_API_URL}/api/approved/`);
            setItems(res.data)
            hideLoader();
        }
        catch (err) {
            console.log(`😱 Axios request failed: ${err}`);
        }
    }
    fetchItems();
}, [showLoader, hideLoader]); // add dependencies here...

暂无
暂无

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

相关问题 React Hook useEffect 缺少依赖项。 包括它们或删除依赖数组 - React Hook useEffect has missing dependencies. Either include them or remove the dependency array React Hook useEffect 缺少依赖项:“颜色”和“选项”。 包括它们或删除依赖数组 - React Hook useEffect has missing dependencies: 'colors' and 'options'. Either include them or remove the dependency array React Hook useEffect 缺少依赖项:“dispatch”和“logout”。 包括它们或删除依赖数组 - React Hook useEffect has missing dependencies: 'dispatch' and 'logout'. Either include them or remove the dependency array 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 React Hook useEffect 缺少依赖项 要么包含它们,要么删除依赖项数组 react-hooks/exhaustive-deps - React Hook useEffect has missing dependencies Either include them or remove the dependency array react-hooks/exhaustive-deps React Hook useEffect 缺少依赖项。 包括它们或删除依赖数组 react-hooks/exhaustive-deps - React Hook useEffect has missing dependencies. Either include them or remove the dependency array react-hooks/exhaustive-deps React Hook useEffect 缺少依赖项:“match.params.id”和“match.params.type”。 包括它们或删除依赖数组 - React Hook useEffect has missing dependencies: 'match.params.id' and 'match.params.type'. Either include them or remove the dependency array React Hook useEffect 缺少一个依赖项:'ans.group._id'。 要么包含它,要么删除依赖数组,为什么? - React Hook useEffect has a missing dependency: 'ans.group._id'. Either include it or remove the dependency array, why? React Hook useEffect 缺少依赖项:&#39;formData&#39;。 包括它或删除依赖项数组。 什么是依赖就是使用 - React Hook useEffect has a missing dependency: 'formData'. Either include it or remove the dependency array. what is dependency is use
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM