So i have this twitter clone where when i follow a user the posts displayed on the index page should refresh and then show the posts from the user i followed and the follow people list should also refresh removing that user. So i have added invalidate tag for the followUser function invalidating both the posts and users data but it is not working. Only when i refresh do i get the updated data. How do i get it so that without refreshing my posts list and user list are refetched and displays new data.
apiSlice followUser
followUser:builder.mutation({
async queryFn({id,currUserId}):Promise<any>{
try{
let currUserDocRef = doc(db,`users/${currUserId}`);
updateDataFirebase(currUserDocRef,'following',id)
return {data:'ok'}
}
catch(err){
return {error:err}
}
},invalidatesTags:['Posts','Users']
})
getPosts
getPosts: builder.query<Posts[],void>({
async queryFn(currUserId):Promise<any>{
try{
let followingsArr=await getFollowingArrFirebase(currUserId);
//console.log(followingsArr)
let tweetsArr: { }[]=[];
const q=query(collection(db,'tweets'), where("creatorId", "in" , followingsArr))
tweetsArr=await getDataFirebase(q)
return { data:tweetsArr }
}
catch(err:any){
return{error:err}
}
},providesTags: ['Posts']}),
solved it. i was not using await before a function call which returned a promise