Skip to content

Commit 792caa4

Browse files
committed
Docs updates
1 parent 8a20f32 commit 792caa4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

docs/routers/create-browser-router.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ const router = createBrowserRouter(
184184

185185
## `unstable_dataStrategy`
186186

187-
<docs-warn>This is a low-level API intended for advanced use-cases. This overrides Remix's internal handling of `loader`/`action` execution, and if done incorrectly will break your app code. Please use with caution and perform the appropriate testing.</docs-warn>
187+
<docs-warning>This is a low-level API intended for advanced use-cases. This overrides Remix's internal handling of `loader`/`action` execution, and if done incorrectly will break your app code. Please use with caution and perform the appropriate testing.</docs-warning>
188188

189-
<docs-warn>This API is marked "unstable" so it is subject to breaking API changes in minor releases</docs-warn>
189+
<docs-warning>This API is marked "unstable" so it is subject to breaking API changes in minor releases</docs-warning>
190190

191191
By default, React Router is opinionated about how your data is loaded/submitted - and most notably, executes all of your loaders in parallel for optimal data fetching. While we think this is the right behavior for most use-cases, we realize that there is no "one size fits all" solution when it comes to data fetching for the wide landscape of application requirements.
192192

@@ -232,17 +232,17 @@ interface HandlerResult {
232232

233233
- **`match.resolve`** - An async function that will resolve any `route.lazy` implementations and execute the route's handler (if necessary), returning a `HandlerResult`
234234
- You should call `match.resolve` for _all_ matches every time to ensure that all lazy routes are properly resolved
235-
- This does not mean you're calling the loader/action (the "handler") - resolve will only call the handler internally if needed and if you don't pass your own `handlerOverride` function parameter
235+
- This does not mean you're calling the loader/action (the "handler") - `resolve` will only call the `handler` internally if needed and if you don't pass your own `handlerOverride` function parameter
236236
- See the examples below for how to implement custom handler execution via `match.resolve`
237237
- **`match.shouldLoad`** - A boolean value indicating whether this route handler needs to be called in this pass
238-
- This array always includes _all_ matched routes even when only _some_ route handlers need to be called so that things like middleware can be implemented
239-
- This is usually only needed if you are skipping the route handler entirely and implementing custom handler logic - since it lets you determine if that custom logic should run for this route or not
238+
- The `matches` array always includes _all_ matched routes even when only _some_ route handlers need to be called so that things like middleware can be implemented
239+
- `shouldLoad` is usually only interesting if you are skipping the route handler entirely and implementing custom handler logic - since it lets you determine if that custom logic should run for this route or not
240240
- For example:
241241
- If you are on `/parent/child/a` and you navigate to `/parent/child/b` - you'll get an array of three matches (`[parent, child, b]`), but only `b` will have `shouldLoad=true` because the data for `parent` and `child` is already loaded
242242
- If you are on `/parent/child/a` and you submit to `a`'s `action`, then only `a` will have `shouldLoad=true` for the action execution of `dataStrategy`
243243
- After the `action`, `dataStrategy` will be called again for the `loader` revalidation, and all matches will have `shouldLoad=true` (assuming no custom `shouldRevalidate` implementations)
244244

245-
The `dataStrategy` function should return a parallel array of `HandlerResult` instances, which is just an object of `{ type: 'data', result: unknown }` or `{ type: 'error', result: unknown }` depending on if the handler was successful or not. If the returned `handlerResult.result` is a `Response`, React Router will unwrap it for you (via `res.json` or `res.text`). If you need to do custom decoding of a `Response` but preserve the status code, you can return the decoded value in `handlerResult.result` and send the status along via `handlerResult.status` (for example, when using the `future.unstable_skipActionRevalidation` flag). `match.resolve()` will return a `HandlerResult` if you are not passing it a handler override function. If you are, then you need to wrap the `handler` result in a `HandlerResult` (see examples below).
245+
The `dataStrategy` function should return a parallel array of `HandlerResult` instances, which indicates if the handler was successful or not. If the returned `handlerResult.result` is a `Response`, React Router will unwrap it for you (via `res.json` or `res.text`). If you need to do custom decoding of a `Response` but preserve the status code, you can return the decoded value in `handlerResult.result` and send the status along via `handlerResult.status` (for example, when using the `future.unstable_skipActionRevalidation` flag). `match.resolve()` will return a `HandlerResult` if you are not passing it a handler override function. If you are, then you need to wrap the `handler` result in a `HandlerResult` (see examples below).
246246

247247
### Example Use Cases
248248

@@ -310,6 +310,8 @@ let router = createBrowserRouter(routes, {
310310
return Promise.all(
311311
matches.map((match, i) =>
312312
match.resolve(async (handler) => {
313+
// Whatever you pass to `handler` will be passed as the 2nd parameter
314+
// to your loader/action
313315
let result = await handler(context);
314316
return { type: "data", result };
315317
})

0 commit comments

Comments
 (0)