Relay Hooks Example App - GitHub Issues Clone
This is an example app that implements a (partial) clone of GitHub's issue feature. The focus is on demonstrating experimental React and Relay features in the context of a real app, including Concurrent Mode, Suspense, and Relay Hooks, which are fully compatible with Concurrent Mode and Suspense out of the box. Key features include:
- Implementing the "render-as-you-fetch" pattern discussed in our React Conf 2019 talk about Suspense for Data-Fetching as well as the React Suspense docs. During route transitions the app is configured to load the code and data for new routes in parallel, rendering whatever is available.
- Using Concurrent Mode and Suspense to improve the loading sequence, including
useTransition()for route transitions in order to continue showing the previous route for a brief period while the next route is prepared/rendered.
- Uses Relay Hooks -
useFragment()and friends - to colocate data-dependencies of components within the components themselves.
- Integrates with React Router primitives to allow preloading of code/data: this is currently a custom integration but we're working with the React Router team to implement support for preloading directly in the framework.
This app is meant for experimentation; we recommend cloning and running locally, hacking on the source code, trying to change things and see how it affects the user experience.
First, clone the app:
git clone email@example.com:relayjs/relay-examples.git
Change into the app's directory:
Install the app's dependencies:
# npm users: npm install # yarn users: yarn
Get your GitHub authentication token in order to let the app query GitHub's public GraphQL API: a. Open https://github.com/settings/tokens. b. Ensure that at least the
reposcope is selected. c. Generate the token d. Create a file
./relay-examples/issue-tracker/.env.localand add the following contents (substiture for your authentication token):
# issue-tracker/.env.local REACT_APP_GITHUB_AUTH_TOKEN=<TOKEN>
Now you're ready to run the app!
Running The App
You can run the app by navigating to
relay-examples/issue-tracker/ and then running the start command:
# npm users: npm start # yarn users: yarn start
This will start the development server (including Relay Compiler) and open a browser to localhost:3000.
About the App
This app uses a number of technologies including (among others):
- Create React App: The app has only a few additions to the default Create React App (CRA) setup - note that these all follow the CRA documentation - the app is not ejected:
- The app follows the steps in https://create-react-app.dev/docs/adding-relay/ to use CRA's built-in support for Relay GraphQL queries.
- The app uses CRA's support for environment variables - https://create-react-app.dev/docs/adding-custom-environment-variables - to allow configuring the GitHub authentication token.
- The app enables prettier for code formatting, as discussed in https://create-react-app.dev/docs/setting-up-your-editor#formatting-code-automatically.
- Note that Create React App itself builds upon many great technologies, see the docs for more details!
- React's experimental release with Concurrent Mode and Suspense.
- Relay's experimental release with Hooks and Concurrent Mode/Suspense compatibility.
- React Router does not yet support preloading data for routes (the React Router team is working on this), so the app uses React Router's primitives instead, specifically the
The available scripts are primarily those defined by Create React App. In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
Note: this is a one-way operation. Once you
eject, you can’t go back!
If you aren’t satisfied with the build tool and configuration choices, you can
eject at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except
eject will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use
eject. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.
To learn Relay, check out the Relay documentation.
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
Analyzing the Bundle Size
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
Making a Progressive Web App
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
yarn build fails to minify
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify