|
| 1 | +# Data Fetching in Decoupled React + Drupal |
| 2 | + |
| 3 | +[back to main project README](../../README.md) |
| 4 | + |
| 5 | +## Summary |
| 6 | + |
| 7 | +The goal for this exercise is to create a React app in Drupal that can fetch data from Drupal using the Drupal JSON API. We'll also look at loading data from an external API. |
| 8 | + |
| 9 | +For an extra challenge, you may use a data fetching library to handle loading states, errors states, and client-side caching. |
| 10 | + |
| 11 | +## Acceptance Criteria |
| 12 | + |
| 13 | +- Add a new React app in Drupal as a block module |
| 14 | + - This can be a new module or feel free to reuse the same custom module from [Part 1](./1-create-custom-react-block.md) |
| 15 | +- Sample content has been added to drupal. |
| 16 | + - The [Devel module](https://www.drupal.org/docs/contributed-modules/devel) can be useful for generating sample content, but you may also add content manually through the Drupal admin. |
| 17 | +- The JSON API module has been enabled in Drupal |
| 18 | +- A fetch request is being made from the The React app to the Drupal JSON API to load Drupal content in our React app. |
| 19 | +- A fetch request is being made from the React app to an external API to display non-drupal content in the same React app. |
| 20 | + - The [PokeAPI](https://pokeapi.co/) is excellent for an external API option |
| 21 | +- [Challenge] A data fetching library is used to handle loading and error states for fetch requests. |
| 22 | +- [Challenge] A data fetching library is used handle client-side caching. |
| 23 | +[TanStack Query](https://tanstack.com/query/latest) is recommended for both Challenge criteria, but there are many other libraries that solve similar problems. |
| 24 | + |
| 25 | +## Helpful Resources |
| 26 | + |
| 27 | +- Documentation: [JSON:API Drupal Docs](https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/api-overview) |
| 28 | +- Tutorial: [JSON:API Resource Requests](https://drupalize.me/tutorial/jsonapi-resource-requests?p=3003) |
| 29 | +- Documentation: [Using the Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) |
| 30 | +- Documentation: [Fetching data with Effects](https://react.dev/reference/react/useEffect#fetching-data-with-effects) |
| 31 | + |
| 32 | +### Extra Challenge Resources |
| 33 | + |
| 34 | +- Documentation: [TanStack Query Docs](https://tanstack.com/query/latest/docs/react/overview)\ |
| 35 | +- Examples: [TanStack Query Examples](https://tanstack.com/query/latest/docs/react/examples/react/basic) |
| 36 | + |
| 37 | +## Setup Instructions |
| 38 | + |
| 39 | +// TODO - Example Solution in-progress |
| 40 | + |
| 41 | + |
0 commit comments