-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])

1
  • For those who wonder about the explanation behind this, here's a good write up Commented Apr 16, 2022 at 9:30

1 Answer 1

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])

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.