Skip to content

Commit

Permalink
Document customizing getKey and getData fetching (#241)
Browse files Browse the repository at this point in the history
* Document customizing getKey and getData fetching (e.g. to pass a different route parameter value to them)

* grammar

* Rephrase

---------

Co-authored-by: Liam Ma <[email protected]>
  • Loading branch information
DmitryGonchar and liamqma authored May 30, 2024
1 parent 51cfc2a commit 55e342e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/resources/creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export const userProfileResource = createResource({
| Property | type | Description |
| --------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `type` | `string` | Used as a namespace for this resource. Each resource should have a unique type |
| `getKey` | `(routerContext, customContext) => string` | The return value of this function is used to identify this resource within the `type` namespace. The function itself is supplied with `routerContext` and `customContext` so that the composition of keys can use this data if required |
| `getData` | `(routerExtendedContext, customContext) => Promise<any>` | This function is used to load the data for the resource. The function should return a promise and resolve with the resource data object. NOTE: You may not use `getData` and `getDataLoader` on the same resource |
| `getKey` | `(routerContext, customContext) => string` | The return value of this function is used to identify this resource within the `type` namespace. The function itself is supplied with `routerContext` and `customContext` so that the composition of keys can use this data if required. `customContext` comes from the top level Router component and its value is equal across resources. `routerContext` contains the current route and location data, which come from the current URL or from a manually provided value (see the ["Accessing resource state for another route or url"](https://atlassian-labs.github.io/react-resource-router/#/resources/usage?id=accessing-resource-state-for-another-route-or-url) section). The router will fetch and cache data for that route then. |
| `getData` | `(routerExtendedContext, customContext) => Promise<any>` | This function is used to load the data for the resource. It is called when initial fetch or `refresh()` is called on the resourse. The function should return a promise and resolve with the resource data object. NOTE: You may not use `getData` and `getDataLoader` on the same resource. |
| `maxAge` | `number` | How long (in milliseconds) the resource should be kept in the router before a fresh resource is retrieved. Note: resources are only refreshed on route _change_. The router does not poll or update resources in the background. Navigation within the same route, e.g. query param change, will not trigger a refresh of resources. |
| `maxCache` | `number` | How many resources can be kept in the router for a particular `type`. Once the threshold limit is reached, a **Least Recently** used resource gets deleted, making space for the new requested resource of the same type. |
| `getDataLoader` | `() => Promise<{default: getData}>` | Optional property that enables neater code splitting. See more below. NOTE: You may not use `getData` and `getDataLoader` on the same resource
| `isBrowserOnly` | `boolean` | Optional property that skips fetching the resource on server. The default value is false. |
| `isBrowserOnly` | `boolean` | Optional property that skips fetching the resource on server. The default value is false. |

0 comments on commit 55e342e

Please sign in to comment.