Untitled

 avatar
unknown
plain_text
a year ago
767 B
16
Indexable
`/*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 };
};
Editor is loading...
Leave a Comment