-1

I want to use async post-get request in useEffect hooks. Is this a optimize solition?

    useEffect(() => {
        await Axios.get("some url").then(async(res) => {
            console.log(res);
        }).catch(async(err) => {
            console.log(err)
        })
    }, [isFocused])
1019 Apps
  • 1
  • 3

1 Answers1

0

I think you can use redux-saga and redux-thunk. But for this problem you can use call another function in your effect function.

    useEffect(() => {
        const fetchData = async () => {
            await Axios.get("some url").then(async (res) => {
                console.log(res);
            }).catch(async (err) => {
                console.log(err)
            })
        }
        fetchData();
    }, [isFocused])