You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs_headless/src/content/docs/common/WithRecord.md
+21-49Lines changed: 21 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,20 @@
1
1
---
2
-
layout: default
3
-
title: "WithRecord"
2
+
title: "<WithRecord>"
4
3
---
5
4
6
-
# `<WithRecord>`
7
-
8
5
`<WithRecord>` grabs the current record from the `RecordContext`. It's the render prop version of [the `useRecordContext` hook](./useRecordContext.md).
9
6
10
7
## Usage
11
8
12
9
The most common use case for `<WithRecord>` is to build a custom field on-the-fly, without creating a new component. For instance, an author field for a book Show view.
@@ -29,64 +24,41 @@ Note that if `record` is undefined, `<WithRecord>` doesn't call the `render` cal
29
24
30
25
As soon as there is a record available, react-admin puts it in a `RecordContext`. This means that `<WithRecord>` works out of the box:
31
26
32
-
- in descendants of the `<Show>` and `<ShowBase>` component
33
-
- in descendants of the `<Edit>` and `<EditBase>` component
34
-
- in descendants of the `<Create>` and `<CreateBase>` component
35
-
- in descendants of the `<DataTable>` component
36
-
- in descendants of the `<Datagrid>` component
37
-
- in descendants of the `<SimpleList>` component
38
-
- in descendants of the `<ReferenceField>` component
39
-
40
-
## Using in a Datagrid
41
-
42
-
When using `<WithRecord>` in a [`<Datagrid>`](./Datagrid.md), you must specify the `label` prop to let react-admin know which field to display in the column header.
**Tip:** You don't need to use `<WithRecord>` if you are using [`<DataTable>`](./DataTable.md), as the [`<DataTable.Col>`](./DataTable.md#datatablecol) component directly provides a [`render`](./DataTable.md#render) prop that works similarly to `<WithRecord>`.
27
+
- in descendants of the `<ShowBase>` component
28
+
- in descendants of the `<EditBase>` component
29
+
- in descendants of the `<CreateBase>` component
30
+
- in descendants of the `<ReferenceFieldBase>` component
31
+
- in descendants of the `<ListIterator>` component
58
32
59
33
## TypeScript
60
34
61
35
The `<WithRecord>` component accepts a generic parameter for the record type:
Copy file name to clipboardExpand all lines: docs_headless/src/content/docs/common/useGetRecordId.md
+1-4Lines changed: 1 addition & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,7 @@
1
1
---
2
-
layout: default
3
2
title: "useGetRecordId"
4
3
---
5
4
6
-
# `useGetRecordId`
7
-
8
5
Accessing the current `recordId` can sometimes be tricky, because it depends on the context in which your component is used.
9
6
10
7
This hook makes it easier to get current `recordId`.
@@ -17,7 +14,7 @@ It will try to obtain it from these 3 sources, in this order:
17
14
This hook accepts a single parameter, `recordId`, which is optional if used inside a `RecordContextProvider` or if `recordId` can be guessed from the URL.
|`anchorOrigin`|`object`| - | The position of the notification. The default is `{ vertical: 'bottom', horizontal: 'center' }`. See [the Material UI documentation](https://mui.com/material-ui/react-snackbar/) for more details. |
55
50
|`autoHideDuration`| `number | null` |`4000`| Duration (in milliseconds) after which the notification hides. Set it to `null` if the notification should not be dismissible. |
56
51
|`messageArgs`|`object`| - | options to pass to the `translate` function (because notification messages are translated if your admin has an `i18nProvider`). It is useful for inserting variables into the translation. |
57
52
|`multiLine`|`boolean`| - | Set it to `true` if the notification message should be shown in more than one line. |
58
53
|`undoable`|`boolean`| - | Set it to `true` if the notification should contain an "undo" button |
59
54
|`type`|`string`|`info`| The notification type (`info`, `success`, `error` or `warning` - the default is `info`) |
60
55
61
-
## `anchorOrigin`
62
-
63
-
You can change the default position of the notification by passing an `anchorOrigin` option. The value is passed to [the Material UI `<Snackbar anchorOrigin>`](https://mui.com/material-ui/react-snackbar/) prop.
You can define a custom delay for hiding a given notification.
75
60
76
61
```jsx
77
-
import { useNotify } from'react-admin';
62
+
import { useNotify } from'ra-core';
78
63
79
64
constLogoutButton= () => {
80
65
constnotify=useNotify();
@@ -90,11 +75,10 @@ const LogoutButton = () => {
90
75
};
91
76
```
92
77
93
-
To change the default delay for all notifications, check [the `<Admin notification>` documentation](./Admin.md#notification).
94
78
95
79
## `messageArgs`
96
80
97
-
`useNotify` calls [the `translate` function](./useTranslate.md) to translate the notification message. You often need to pass variables to the `translate` function. The `messageArgs` option allows you to do that.
81
+
`useNotify` calls [the `translate` function](../i18n/useTranslate.md) to translate the notification message. You often need to pass variables to the `translate` function. The `messageArgs` option allows you to do that.
98
82
99
83
For instance, if you want to display a notification message like "Post 123 created", you need to pass the post id to the translation function.
100
84
@@ -118,7 +102,7 @@ Then, in your translation files, you can use the `id` variable:
Finally, `messageArgs` lets you define a `smart_count` variable, which is useful for [pluralization](./useTranslate.md#using-pluralization-and-interpolation):
105
+
Finally, `messageArgs` lets you define a `smart_count` variable, which is useful for [pluralization](../i18n/useTranslate.md#using-pluralization-and-interpolation):
@@ -160,10 +144,9 @@ notify('This is an error', { type: 'error' });
160
144
161
145
When using `useNotify` as a side effect for an `undoable` mutation, you MUST set the `undoable` option to `true`, otherwise the "undo" button will not appear, and the actual update will never occur.
You may want a notification message that contains HTML or other React components. To do so, you can pass a React node as the first argument of the `notify` function.
189
171
190
-
This allows e.g. using [Material UI's `<Alert>` component](https://mui.com/material-ui/react-snackbar/#customization) to display a notification with a custom icon, color, or action.
191
-
192
-

Note that if you use this ability to pass a React node, the message will not be translated - you'll have to translate it yourself using [`useTranslate`](./useTranslate.md).
207
+
Note that if you use this ability to pass a React node, the message will not be translated - you'll have to translate it yourself using [`useTranslate`](../i18n/useTranslate.md).
231
208
232
209
## Closing The Notification
233
210
234
211
If you have custom actions in your notification element, you can leverage the `useCloseNotification` hook to close the notification programmatically:
0 commit comments