Actualización a Dic-2020
Ahora se importa una única dependencia de Apollo y GraphQL
npm install @apollo/client graphql
Luego en el index principal
//DEPENDENCIES
import React from "react";
import ReactDOM from "react-dom";
import { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client";
//APP
import App from "./App";
const client = new ApolloClient({
uri: "https://petgram-server-clgg.vercel.app/graphql",
cache: new InMemoryCache(),
});
ReactDOM.render(
<ApolloProvider client={client}>
<App />
</ApolloProvider>,
document.getElementById("App")
);
Y en ListOfPhotocards
//DEPENDENCIES
import React from "react";
import { useQuery, gql } from "@apollo/client";
//COMPONENTS
import { PhotoCard } from "../PhotoCard";
const whitPhotos = gql`
query getPhotos {
photos {
id
categoryId
src
likes
userId
liked
}
}
`;
export const ListOfPhotoCards = () => {
const { loading, error, data } = useQuery(whitPhotos);
if (error) {
return <h2>Internal Server Error</h2>;
}
if (loading) {
return <h2>Loading...</h2>;
}
return (
<ul>
{data.photos.map((photo) => (
<PhotoCard key={photo.id} {...photo} />
))}
</ul>
);
};
😉
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?
o inicia sesión.