Skip to content

Commit

Permalink
Fix Aside doc for undefined record
Browse files Browse the repository at this point in the history
Closes #2511
  • Loading branch information
fzaninotto committed Nov 8, 2018
1 parent a209555 commit c6e90ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions docs/CreateEdit.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,18 @@ The `aside` component receives the same props as the `Edit` or `Create` child co
const Aside = ({ record }) => (
<div style={{ width: 200, margin: '1em' }}>
<Typography variant="title">Post details</Typography>
<Typography variant="body1">
Creation date: {record.createdAt}
</Typography>
{record && (
<Typography variant="body1">
Creation date: {record.createdAt}
</Typography>
)}
</div>
);
```
{% endraw %}
**Tip**: Always test that the `record` is defined before using it, as react-admin starts rendering the UI before the API call is over.
## Prefilling a `<Create>` Record
You may need to prepopulate a record based on another one. For that use case, use the `<CloneButton>` component. It expects a `record` and a `basePath` (usually injected to children of `<Datagrid>`, `<SimpleForm>`, `<SimpleShowLayout>`, etc.), so it's as simple to use as a regular field or input.
Expand Down
10 changes: 7 additions & 3 deletions docs/Show.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,18 @@ The `aside` component receives the same props as the `Show` child component: `ba
const Aside = ({ record }) => (
<div style={{ width: 200, margin: '1em' }}>
<Typography variant="title">Post details</Typography>
<Typography variant="body1">
Creation date: {record.createdAt}
</Typography>
{record && (
<Typography variant="body1">
Creation date: {record.createdAt}
</Typography>
)}
</div>
);
```
{% endraw %}
**Tip**: Always test that the `record` is defined before using it, as react-admin starts rendering the UI before the API call is over.
## The `<ShowGuesser>` component
Instead of a custom `Show`, you can use the `ShowGuesser` to determine which fields to use based on the data returned by the API.
Expand Down

0 comments on commit c6e90ea

Please sign in to comment.