Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Dec 17, 2024
1 parent 23e0c63 commit 437bfa2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/Create.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ You can do the same for error notifications, by passing a custom `onError` call

You sometimes need to pre-populate a record based on a *related* record. For instance, to create a comment related to an existing post.

By default, the `<Create>` view starts with an empty `record`. However, if the `location` object (injected by [react-router-dom](https://reacttraining.com/react-router/web/api/location)) contains a `record` in its `state`, the `<Create>` view uses that `record` instead of the empty object. That's how the `<CloneButton>` works under the hood.
By default, the `<Create>` view starts with an empty `record`. However, if the `location` object (injected by [react-router-dom](https://reactrouter.com/6.28.0/start/concepts#locations)) contains a `record` in its `state`, the `<Create>` view uses that `record` instead of the empty object. That's how the `<CloneButton>` works under the hood.

That means that if you want to create a link to a creation form, presetting *some* values, all you have to do is to set the `state` prop of the `<CreateButton>`:

Expand Down
8 changes: 3 additions & 5 deletions docs/Edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -791,17 +791,16 @@ You can do the same for error notifications, by passing a custom `onError` call

You sometimes need to pre-populate the form changes to a record. For instance, to revert a record to a previous version, or to make some changes while letting users modify others fields as well.

By default, the `<Edit>` view starts with the current `record`. However, if the `location` object (injected by [react-router-dom](https://reacttraining.com/react-router/web/api/location)) contains a `record` in its `state`, the `<Edit>` view uses that `record` to prefill the form.
By default, the `<Edit>` view starts with the current `record`. However, if the `location` object (injected by [react-router-dom](https://reactrouter.com/6.28.0/start/concepts#locations)) contains a `record` in its `state`, the `<Edit>` view uses that `record` to prefill the form.

That means that if you want to create a link to an edition view, modifying immediately *some* values, all you have to do is to set the `state` prop of the `<EditButton>`:

{% raw %}
```jsx
import * as React from 'react';
import { EditButton, Datagrid, List, useRecordContext } from 'react-admin';
import { EditButton, Datagrid, List } from 'react-admin';

const ApproveButton = () => {
const record = useRecordContext();
return (
<EditButton
state={{ record: { status: 'approved' } }}
Expand All @@ -825,10 +824,9 @@ export default PostList = () => (
{% raw %}
```jsx
import * as React from 'react';
import { CreateButton, useRecordContext } from 'react-admin';
import { EditButton } from 'react-admin';

const ApproveButton = () => {
const record = useRecordContext();
return (
<EditButton
to={{
Expand Down
1 change: 1 addition & 0 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ title: "Index"

**- R -**
* [`useRecordContext`](./useRecordContext.md)
* [`useRecordFromLocation`](./useRecordFromLocation.md)
* [`useRedirect`](./useRedirect.md)
* [`useReference`](./useGetOne.md#aggregating-getone-calls)
* [`useRefresh`](./useRefresh.md)
Expand Down
1 change: 1 addition & 0 deletions docs/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<li {% if page.path == 'useEditContext.md' %} class="active" {% endif %}><a class="nav-link" href="./useEditContext.html"><code>useEditContext</code></a></li>
<li {% if page.path == 'useEditController.md' %} class="active" {% endif %}><a class="nav-link" href="./useEditController.html"><code>useEditController</code></a></li>
<li {% if page.path == 'useSaveContext.md' %} class="active" {% endif %}><a class="nav-link" href="./useSaveContext.html"><code>useSaveContext</code></a></li>
<li {% if page.path == 'useRecordFromLocation.md' %} class="active" {% endif %}><a class="nav-link" href="./useRecordFromLocation.html"><code>useRecordFromLocation</code></a></li>
<li {% if page.path == 'useRegisterMutationMiddleware.md' %} class="active" {% endif %}><a class="nav-link" href="./useRegisterMutationMiddleware.html"><code>useRegisterMutationMiddleware</code></a></li>
<li {% if page.path == 'useUnique.md' %} class="active" {% endif %}><a class="nav-link" href="./useUnique.html"><code>useUnique</code></a></li>
</ul>
Expand Down

0 comments on commit 437bfa2

Please sign in to comment.