Home > Software design >  I have a data list in data.data, while using React fetch I use setEducation(data.data). How can I us
I have a data list in data.data, while using React fetch I use setEducation(data.data). How can I us

Time:11-04

    //try to setEducation(data.data) using React Query//
    const { data, isLoading, refetch } = useQuery(['available', user?.email], () => fetch(`http://localhost:5000/education/${user?.email}`)
        .then(res => res.json()))
    if(isLoading){
        return <Loading></Loading>
    }


//It is working for React default fetch//
useEffect(()=>{
        fetch(`http://localhost:5000/education/${user?.email}`)
        .then(res=>res.json())
        .then(data=>setEducation(data.data))
        setLoading(false)
    },[user?.email])

I try to find the result from data.data by using react query.

CodePudding user response:

In useEffect you ues setEducation() but in for question you use setData() Can you check if their any typing mistakes.

CodePudding user response:

In React Query, you do not need to use setData(). You can get your data from data.data by using destructure. An example is given below.

const {id, name, school} = data.data
  • Related