Skip to content

Commit

Permalink
Update examples in docs and add notes about resources plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Lamont committed Nov 27, 2023
1 parent b0e55fa commit f800c3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,22 @@ export const appRoutes = [

### Use the Router

Now that you've set up your resources, components and configuration correctly, all you need to do is mount the [Router](api/components.md#router) in your react tree with a [`RouteComponent`](api/components.md#routecomponent) as a child. It will do the rest!
Now that you've set up your resources, components and configuration correctly, all you need to do is mount the [Router](api/components.md#router) with the [Resources Plugin](api/components?id=resources-plugin) in your react tree, and a [`RouteComponent`](api/components.md#routecomponent) as a child. It will do the rest!

```js
import {
Router,
RouteComponent,
createBrowserHistory,
} from 'react-resource-router';
import {createResourcesPlugin} from "react-resource-router/resources";
import { appRoutes } from './routing/routes';

const history = createBrowserHistory();
const resourcesPlugin = createResourcesPlugin({});

const App = () => (
<Router routes={appRoutes} history={history}>
<Router routes={appRoutes} history={history} plugins={[resourcesPlugin]}>
<RouteComponent />
</Router>
);
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/concept.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Router Resources are objects that are used by the router to fetch, cache and pro
You can create these objects using the [`createResource`](./creation.md) function and then put them in the `resources` array on your route configuration object. Doing so means that each resources' data will be fetched as soon as the Router is mounted on initial page loads and on route transitions if the resources have expired.

Since we recommend that your [`Router`](../api/components.md#router) sits as high up in your React tree as possible, it means that asynchronous requests for data are triggered as early as can be. This results in quicker meaningful render times.

When using resources, you should initialise the resources plugin with [`createResourcesPlugin`](../api/components?id=resources-plugin), and ensure that this is loaded as a plugin when calling [`Router`](../api/components.md#router) in your app.

0 comments on commit f800c3a

Please sign in to comment.