How can I use an item (function) outside from UseEffect hook?

Viewed 24

This is the code in question:

    useEffect(() => {
    setStart(start + count);
    const fetchImages = () => {
      axios
        .get(`/api/photos?count=${count}&start=${start}`)
        .then((res) => setImages(images, ...res.data));
      fetchImages();
    };
  }, []);

How can I use fetchImages outside of the useEffect hook?

1 Answers

You need to put fetchImages outside of useEffect and wrap it with useCallback and then you can use fetchImages outside of useEffect and inside the useEffect as well

Related