当我移动下一页或移动到另一个页面或更新数据时...数据不重新获取...当我重新加载页面然后重新获取数据...无需重新加载如何使用 RTK 查询重新获取数据..
这是代码
export const userService = createApi({
reducerPath: 'userService',
baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:5000/api/user/' }),
tagTypes: ["Userdetail",'Profile_update'],
endpoints: (builder) => ({
getuserdetails: builder.query({
query: () => ({
url: 'userdetails',
// method: 'GET',
headers: {
'Content-type': 'application/json',
'auth-token': localStorage.getItem('loginToken')
}
}),
providesTags : ['Userdetail']
}),
updateuserdetail: builder.mutation({
query: (newbody) => {
const {id,...data} = newbody
return{
url: `profile_update/${id}`,
method: 'PUT',
body: data,
headers: {
'Content-type': 'application/json',
'auth-token': localStorage.getItem('loginToken')
}
}
},
invalidatesTags :['Profile_update']
}),
})
})
Run Code Online (Sandbox Code Playgroud)
当渲染其他内容时调用 useGetuserdetailsQuery 每个组件
function …Run Code Online (Sandbox Code Playgroud)