I'm trying to get the list of the chats in my app using react-query(useQuery). my API call is in a different component and I'm using Axios to get the data. but the component is returning the function itself not the data .which part is Wrong?
import { useQuery } from "react-query";
import axios from "axios";
const getContacts = async () => {
const headers = { Authorization: localStorage.getItem("token") };
const options = {
method: "GET",
url: "http://127.0.0.1:8000/chat/mine/",
headers: headers,
};
const { data } = await axios.request(options);
return data;
};
function GetUserDataUseQuery() {
return useQuery("getContacts", getContacts);
}
export default GetUserDataUseQuery;
function getUserData() {
const data = GetUserDataUseQuery;
return (dispatch) => {
dispatch({
type: GET_CONTACTS,
payload: [],
});
};
}
getUserDatafunction is supposed to do, also,const data = GetUserDataUseQuery;should beconst data = useUserData()(change to lower case and rename for best practice)` since that's a hookgetUserDatareturns a function, and I don't see any components, so what's your question?getUserDatafunction has been used in a component and actually dispatches the values to reducer .and I didn't useuseUserDatabecausegetUserDatais not in a component.I've used this type of code foruseMutationand it worked correctlygetUserDataon loading .getUserDatais actually an action to dispatch data to reducer