Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
767 B
4
Indexable
Never
`/*above this, is writen standard code for apollo configuration client */

 export const useBlogPostsHomeData = () => {
  const [posts, setPosts] = useState([]);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState(null);

  const fetchPostsData = async () => {
    const query = gql`
      query Posts {
        posts(first: 3) {
          nodes {
            author {
          }
        }
      }
    `;

    try {
      const result = await fetchData(query);
      setPosts(result.posts.nodes);
      setLoading(false);
    } catch (error) {
      setError(error);
      setLoading(false);
    }
  };

  useEffect(() => {
    fetchPostsData();
  });

  return { posts, loading, error, posts };
};
Leave a Comment