Skip to content

Instantly share code, notes, and snippets.

@yuritoledo
Created May 4, 2021 21:51
Show Gist options
  • Save yuritoledo/1f5965d26075f18557753f4d10bd02c2 to your computer and use it in GitHub Desktop.
Save yuritoledo/1f5965d26075f18557753f4d10bd02c2 to your computer and use it in GitHub Desktop.
/**
* In this short assessment, the following code tries to implement the React Suspense API,
* but does so incorrectly. There are 3 core issues with how these components utilize Suspense and concurrent mode -- can you find them?
*
* In your submission, be sure to:
* 1) Clearly identify what the 3 core issues are, and how they violate the principles of React Suspense;
* 2) Write and submit the code to fix the core issues you have identified in a gist of your own
*
* If you aren't familiar with Suspense, the docs are a good starting place:
*
* https://reactjs.org/docs/concurrent-mode-intro.html
*
* We rate each answer by comparing the submitted answer to how we would write the same code in production at Contra.
* You are guaranteed an interview if your code ticks all the boxes. Good luck!
*/
import { Suspense, useState, useEffect, lazy } from 'react';
import { useQuery } from 'react-apollo'
const SpinnerLoader = lazy(() => import('../component/SpinnerLoader'))
const SuspensefulUserProfile = ({ userId }) => {
const { data } = useQuery('myQuery', { suspend: true });
return (
<Suspense fallback={SpinnerLoader}>
<UserProfile data={data} />
</Suspense>
);
};
const UserProfile = ({ data }) => {
return (
<>
<h1>{data.name}</h1>
<h2>{data.email}</h2>
</>
);
};
const UserProfileList = () => (
<>
<SuspensefulUserProfile userId={1} />
<SuspensefulUserProfile userId={2} />
<SuspensefulUserProfile userId={3} />
</>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment