I am trying to follow Mosh lesson to fetch data from API using apisuace.
But it keep return me null value when i try to print using console.log(response.data) after api call.
const [listings, setListings] = useState([]);
useEffect(() => {
loadListings();
}, []);
const loadListings = async () => {
const response = await listingsApi.getListings();
console.log(response.data);
setListings(response.data);
};
Here is my client.js file.
import { create } from "apisauce";
const apiClient = create({
baseURL: "http://127.0.0.1:9000/api",
});
export default apiClient;
I also tried to access the following url from my web browser the data is showing.
``Is anyone know what is the problem? Thanks a lot!.