Skip to content

Commit

Permalink
Add Suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
flexbox committed Apr 24, 2019
1 parent 3bd73ce commit 63ddbbc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
18 changes: 11 additions & 7 deletions 6-suspense/app/src/App.js
@@ -1,13 +1,17 @@
import React from "react";
import Profile from "./Profile";
import Repositories from "./Repositories";
import React, { Suspense } from 'react';
import Profile from './Profile';
import Repositories from './Repositories';

function App() {
return (
<div>
<Profile />
<Repositories />
</div>
<>
<Suspense fallback={<div>Loading...</div>}>
<Profile />
</Suspense>
<Suspense fallback={<div>Loading...</div>}>
<Repositories />
</Suspense>
</>
);
}

Expand Down
11 changes: 4 additions & 7 deletions 6-suspense/app/src/Profile.js
@@ -1,6 +1,6 @@
import React from "react";
import gql from "graphql-tag";
import { useQuery } from "react-apollo-hooks";
import React from 'react';
import gql from 'graphql-tag';
import { useQuery } from 'react-apollo-hooks';

const profileQuery = gql`
{
Expand All @@ -13,10 +13,7 @@ const profileQuery = gql`
`;

function Profile() {
const { loading, data, error } = useQuery(profileQuery);
if (loading) {
return <div>Loading ...</div>;
}
const { data, error } = useQuery(profileQuery, { suspend: true });
if (error) {
return <div>Error: {error.message}</div>;
}
Expand Down
11 changes: 4 additions & 7 deletions 6-suspense/app/src/Repositories.js
@@ -1,6 +1,6 @@
import React from "react";
import gql from "graphql-tag";
import { useQuery } from "react-apollo-hooks";
import React from 'react';
import gql from 'graphql-tag';
import { useQuery } from 'react-apollo-hooks';

const repositoriesQuery = gql`
{
Expand All @@ -16,10 +16,7 @@ const repositoriesQuery = gql`
`;

function Repositories() {
const { loading, data, error } = useQuery(repositoriesQuery);
if (loading) {
return <div>Loading ...</div>;
}
const { data, error } = useQuery(repositoriesQuery, { suspend: true });
if (error) {
return <div>Error: {error.message}</div>;
}
Expand Down

0 comments on commit 63ddbbc

Please sign in to comment.