Skip to content

Commit

Permalink
docs: Document route render methods returning functions (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
taion authored Mar 7, 2019
1 parent 0978d13 commit b95e8f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,24 @@ This should be a relatively rare scenario, as generally user experience is bette

#### `render`

Specify the `render` method to further customize how the route renders. This method should return a React element to render that element, `undefined` if it has a pending asynchronous component or data dependency and is not ready to render, or `null` to render no component. It receives an object with the following properties:
Specify the `render` method to further customize how the route renders. It receives an object with the following properties:

- `match`: the routing state object, as above
- `Component`: the component for the route, if any; `null` if the component has not yet been loaded
- `props`: the default props for the route component, specifically `match` with `data` as an additional property; `null` if `data` have not yet been loaded
- `data`: the data for the route, as above; `null` if the data have not yet been loaded

Note that, when specifying this `render` method, `Component` or `getComponent` will have no effect other than controlling the value of the `Component` property on the argument to `render`.
It should return:

- another function that receives its children as an argument and returns a React element; this function receives
- a React element when not using named child routes
- an object when using named child routes
- `null` when it has no children
- a React element to render that element
- `undefined` if it has a pending asynchronous component or data dependency and is not ready to render
- `null` to render its children (or nothing of there are no children)

Note that, when specifying this `render` method, `Component` or `getComponent` will have no effect other than controlling the value of the `Component` property on the argument to `render`. Additionally, the behavior is different between returning a function that returns `null` and returning `null` directly; in the former case, nothing will be rendered, while in the latter case, the route's children will be rendered.

You can use this method to render per-route loading state.

Expand Down
2 changes: 1 addition & 1 deletion src/ElementsRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const propTypes = {

function accumulateElement(children, element) {
if (!children) {
return typeof element === 'function' ? element() : element;
return typeof element === 'function' ? element(null) : element;
}

if (!element) {
Expand Down

0 comments on commit b95e8f5

Please sign in to comment.