News for hackers. Stuff that matters.
Re:React Suspense by typon on Thursday December 05, 2019 @09:21AM (#21712424)
What's the difference between this and using Apollo Graphql for requests?
Re:React Suspense by bobobooey on Thursday December 05, 2019 @09:35AM (#21712526)
Not sure what you mean...GraphQL is just the API endpoint. Using GQL or REST wouldn't make a difference on how suspense works.

You'd still query and display your data in the same way. Suspense will just be a wrapper around the component displaying the data.

Re:React Suspense by typon on Thursday December 05, 2019 @02:46PM (#21715749)
Consider this code snippet using Apollo React Client:

    const Dogs = ({ onDogSelected }) => (
      <Query query={GET_DOGS}>
        {({ loading, error, data }) => {
          if (loading) return 'Loading...';
          if (error) return `Error! ${error.message}`;

          return (
            <select name="dog" onChange={onDogSelected}>
              {data.dogs.map(dog => (
                <option key={dog.id} value={dog.breed}>
                  {dog.breed}
                </option>
              ))}
            </select>
          );
        }}
      </Query>
    );
Re:React Suspense by bobobooey on Thursday December 05, 2019 @09:06PM (#21718686)
You could still wrap this in a suspense wrapper.
Re:React Suspense by choward on Thursday December 05, 2019 @09:59AM (#21712770)
With GraphQL you could in theory grab all the data a page needs in one request. Suspense seems to only be useful if you are making multiple requests. Not sure what Apollo has to do with anything though.
Re:React Suspense by bobobooey on Thursday December 05, 2019 @10:24AM (#21713058)
Isn't still possible to wait for the data from that one request to be loaded? I'm also curious on how this will work with subscriptions.
Re:React Suspense by maaaats on Thursday December 05, 2019 @10:24AM (#21713065)
Graphql is for fetching exactly the data your app needs at that point, suspense is for fetching only the code the app needs at that point.