-1

How can I remove warnings like this error src\components\pages\badge\BadgeScreen.tsx Line 87:6: React Hook useEffect has a missing dependency: 'loadData'. Either include it or remove the dependency array react-hooks/exhaustive-deps

Here is my code:

const location = useLocation();
  const { badge }: any = location.state;

    const [data, setData] = useState({
        id: "",
        badge_name: "",
        badge_description: "",
        imgBase64: "",
        img_icon: "",
      });
    
            useEffect(() => {
            setData(badge);
          }, [badge]);

Everything is working fine, but I am having a hard time fixing this issue.

Thank you!

Asdf1234567
  • 476
  • 1
  • 10
  • 25
  • 1
    That isn't the code the warning is warning you about. It doesn't use `loadData` at all. – Quentin Feb 15 '22 at 13:55
  • Possible clone of https://stackoverflow.com/questions/55840294/how-to-fix-missing-dependency-warning-when-using-useeffect-react-hook – Master.Deep Feb 15 '22 at 13:56

1 Answers1

0

I think you don't need useEffect because you can setData after location.state destructuring.

For example:

const location = useLocation();
const { badge }: any = location.state;
const [data, setData] = useState(badge);