Skip to content

Commit 29f658d

Browse files
authored
Merge pull request #8337 from marmelab/docs-jsdoc-fixes
[Doc] Update jsDocs to access record from context instead of props
2 parents fd9f245 + c7f75d4 commit 29f658d

14 files changed

+68
-43
lines changed

packages/ra-core/src/dataProvider/useCreate.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ import { RaRecord, CreateParams } from '../types';
3939
*
4040
* @example // set params when calling the create callback
4141
*
42-
* import { useCreate } from 'react-admin';
42+
* import { useCreate, useRecordContext } from 'react-admin';
4343
*
44-
* const LikeButton = ({ record }) => {
44+
* const LikeButton = () => {
45+
* const record = useRecordContext();
4546
* const like = { postId: record.id };
4647
* const [create, { isLoading, error }] = useCreate();
4748
* const handleClick = () => {
@@ -53,9 +54,10 @@ import { RaRecord, CreateParams } from '../types';
5354
*
5455
* @example // set params when calling the hook
5556
*
56-
* import { useCreate } from 'react-admin';
57+
* import { useCreate, useRecordContext } from 'react-admin';
5758
*
58-
* const LikeButton = ({ record }) => {
59+
* const LikeButton = () => {
60+
* const record = useRecordContext();
5961
* const like = { postId: record.id };
6062
* const [create, { isLoading, error }] = useCreate('likes', { data: like });
6163
* if (error) { return <p>ERROR</p>; }

packages/ra-core/src/dataProvider/useDelete.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ import {
4848
*
4949
* @example // set params when calling the deleteOne callback
5050
*
51-
* import { useDelete } from 'react-admin';
51+
* import { useDelete, useRecordContext } from 'react-admin';
5252
*
53-
* const DeleteButton = ({ record }) => {
53+
* const DeleteButton = () => {
54+
* const record = useRecordContext();
5455
* const [deleteOne, { isLoading, error }] = useDelete();
5556
* const handleClick = () => {
5657
* deleteOne('likes', { id: record.id, previousData: record })
@@ -61,9 +62,10 @@ import {
6162
*
6263
* @example // set params when calling the hook
6364
*
64-
* import { useDelete } from 'react-admin';
65+
* import { useDelete, useRecordContext } from 'react-admin';
6566
*
66-
* const DeleteButton = ({ record }) => {
67+
* const DeleteButton = () => {
68+
* const record = useRecordContext();
6769
* const [deleteOne, { isLoading, error }] = useDelete('likes', { id: record.id, previousData: record });
6870
* if (error) { return <p>ERROR</p>; }
6971
* return <button disabled={isLoading} onClick={() => deleteOne()}>Delete</button>;

packages/ra-core/src/dataProvider/useGetManyAggregate.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ import { useDataProvider } from './useDataProvider';
4949
*
5050
* @example
5151
*
52-
* import { useGetManyAggregate } from 'react-admin';
52+
* import { useGetManyAggregate, useRecordContext } from 'react-admin';
5353
*
54-
* const PostTags = ({ record }) => {
54+
* const PostTags = () => {
55+
* const record = useRecordContext();
5556
* const { data, isLoading, error } = useGetManyAggregate('tags', { ids: record.tagIds });
5657
* if (isLoading) { return <Loading />; }
5758
* if (error) { return <p>ERROR</p>; }

packages/ra-core/src/dataProvider/useGetManyReference.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ import { useDataProvider } from './useDataProvider';
3939
* @prop params.filter The request filters, e.g. { title: 'hello, world' }
4040
* @prop params.meta Optional meta parameters
4141
*
42-
*
4342
* @returns The current request state. Destructure as { data, total, error, isLoading, refetch }.
4443
*
4544
* @example
4645
*
47-
* import { useGetManyReference } from 'react-admin';
46+
* import { useGetManyReference, useRecordContext } from 'react-admin';
4847
*
49-
* const PostComments = ({ record }) => {
48+
* const PostComments = () => {
49+
* const record = useRecordContext();
5050
* // fetch all comments related to the current record
5151
* const { data, isLoading, error } = useGetManyReference(
5252
* 'comments',

packages/ra-core/src/dataProvider/useGetOne.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ import { useDataProvider } from './useDataProvider';
3131
*
3232
* @example
3333
*
34-
* import { useGetOne } from 'react-admin';
34+
* import { useGetOne, useRecordContext } from 'react-admin';
3535
*
36-
* const UserProfile = ({ record }) => {
36+
* const UserProfile = () => {
37+
* const record = useRecordContext();
3738
* const { data, isLoading, error } = useGetOne('users', { id: record.id });
3839
* if (isLoading) { return <Loading />; }
3940
* if (error) { return <p>ERROR</p>; }

packages/ra-core/src/dataProvider/useUpdate.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ import {
5050
*
5151
* @example // set params when calling the update callback
5252
*
53-
* import { useUpdate } from 'react-admin';
53+
* import { useUpdate, useRecordContext } from 'react-admin';
5454
*
55-
* const IncreaseLikeButton = ({ record }) => {
55+
* const IncreaseLikeButton = () => {
56+
* const record = useRecordContext();
5657
* const diff = { likes: record.likes + 1 };
5758
* const [update, { isLoading, error }] = useUpdate();
5859
* const handleClick = () => {
@@ -64,9 +65,10 @@ import {
6465
*
6566
* @example // set params when calling the hook
6667
*
67-
* import { useUpdate } from 'react-admin';
68+
* import { useUpdate, useRecordContext } from 'react-admin';
6869
*
69-
* const IncreaseLikeButton = ({ record }) => {
70+
* const IncreaseLikeButton = () => {
71+
* const record = useRecordContext();
7072
* const diff = { likes: record.likes + 1 };
7173
* const [update, { isLoading, error }] = useUpdate('likes', { id: record.id, data: diff, previousData: record });
7274
* if (error) { return <p>ERROR</p>; }

packages/ra-core/src/dataProvider/useUpdateMany.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ import { Identifier } from '..';
5050
*
5151
* @example // set params when calling the updateMany callback
5252
*
53-
* import { useUpdateMany } from 'react-admin';
53+
* import { useUpdateMany, useListContext } from 'react-admin';
5454
*
55-
* const BulkResetViewsButton = ({ selectedIds }) => {
55+
* const BulkResetViewsButton = () => {
56+
* const { selectedIds } = useListContext();
5657
* const [updateMany, { isLoading, error }] = useUpdateMany();
5758
* const handleClick = () => {
5859
* updateMany('posts', { ids: selectedIds, data: { views: 0 } });
@@ -63,9 +64,10 @@ import { Identifier } from '..';
6364
*
6465
* @example // set params when calling the hook
6566
*
66-
* import { useUpdateMany } from 'react-admin';
67+
* import { useUpdateMany, useListContext } from 'react-admin';
6768
*
68-
* const BulkResetViewsButton = ({ selectedIds }) => {
69+
* const BulkResetViewsButton = () => {
70+
* const { selectedIds } = useListContext();
6971
* const [updateMany, { isLoading, error }] = useUpdateMany('posts', { ids: selectedIds, data: { views: 0 } });
7072
* if (error) { return <p>ERROR</p>; }
7173
* return <button disabled={isLoading} onClick={() => updateMany()}>Reset views</button>;

packages/ra-ui-materialui/src/button/ShowButton.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ import { Button, ButtonProps } from './Button';
1616
* Opens the Show view of a given record
1717
*
1818
* @example // basic usage
19-
* import { ShowButton } from 'react-admin';
19+
* import { ShowButton, useRecordContext } from 'react-admin';
2020
*
21-
* const CommentShowButton = ({ record }) => (
22-
* <ShowButton label="Show comment" record={record} />
23-
* );
21+
* const CommentShowButton = () => {
22+
* const record = useRecordContext();
23+
* return (
24+
* <ShowButton label="Show comment" record={record} />
25+
* );
26+
* };
2427
*/
2528
const ShowButton = <RecordType extends RaRecord = any>(
2629
props: ShowButtonProps<RecordType>

packages/ra-ui-materialui/src/detail/EditActions.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import TopToolbar from '../layout/TopToolbar';
1414
*
1515
* @example
1616
* import Button from '@mui/material/Button';
17-
* import { TopToolbar, ShowButton, Edit } from 'react-admin';
17+
* import { TopToolbar, EditButton, Edit } from 'react-admin';
1818
*
19-
* const PostEditActions = ({ record, resource }) => (
19+
* const PostEditActions = () => (
2020
* <TopToolbar>
21-
* <ShowButton record={record} />
21+
* <EditButton />
2222
* // Add your custom actions here
2323
* <Button color="primary" onClick={customAction}>Custom Action</Button>
2424
* </TopToolbar>

packages/ra-ui-materialui/src/detail/ShowActions.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import TopToolbar from '../layout/TopToolbar';
1414
*
1515
* @example
1616
* import Button from '@mui/material/Button';
17-
* import { TopToolbar, EditButton, Show } from 'react-admin';
17+
* import { TopToolbar, ShowButton, Show } from 'react-admin';
1818
*
19-
* const PostShowActions = ({ record, resource }) => (
19+
* const PostShowActions = () => (
2020
* <TopToolbar>
21-
* <EditButton record={record} />
21+
* <ShowButton />
2222
* // Add your custom actions here //
2323
* <Button color="primary" onClick={customAction}>Custom Action</Button>
2424
* </TopToolbar>

packages/ra-ui-materialui/src/field/ArrayField.tsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ import { PublicFieldProps, InjectedFieldProps, fieldPropTypes } from './types';
6161
* to write your own component:
6262
*
6363
* @example
64-
* const TagsField = ({ record }) => (
65-
* <ul>
66-
* {record.tags.map(item => (
67-
* <li key={item.name}>{item.name}</li>
68-
* ))}
69-
* </ul>
70-
* );
64+
* const TagsField = () => {
65+
* const record = useRecordContext();
66+
* return (
67+
* <ul>
68+
* {record.tags.map(item => (
69+
* <li key={item.name}>{item.name}</li>
70+
* ))}
71+
* </ul>
72+
* );
73+
* };
7174
*/
7275
export const ArrayField: FC<ArrayFieldProps> = memo(props => {
7376
const { children, resource, source } = props;

packages/ra-ui-materialui/src/field/SelectField.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ import { PublicFieldProps, InjectedFieldProps, fieldPropTypes } from './types';
5555
* { id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
5656
* { id: 456, first_name: 'Jane', last_name: 'Austen' },
5757
* ];
58-
* const FullNameField = ({ record }) => <Chip>{record.first_name} {record.last_name}</Chip>;
58+
* const FullNameField = () => {
59+
* const record = useRecordContext();
60+
* return (<Chip>{record.first_name} {record.last_name}</Chip>)
61+
* };
5962
* <SelectField source="gender" choices={choices} optionText={<FullNameField />}/>
6063
*
6164
* The current choice is translated by default, so you can use translation identifiers as choices:

packages/ra-ui-materialui/src/input/RadioButtonGroupInput.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ import { LinearProgress } from '../layout';
6060
* { id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
6161
* { id: 456, first_name: 'Jane', last_name: 'Austen' },
6262
* ];
63-
* const FullNameField = ({ record }) => <span>{record.first_name} {record.last_name}</span>;
63+
* const FullNameField = () => {
64+
* const record = useRecordContext();
65+
* return (<span>{record.first_name} {record.last_name}</span>)
66+
* };
6467
* <RadioButtonGroupInput source="recipients" choices={choices} optionText={<FullNameField />}/>
6568
*
6669
* The choices are translated by default, so you can use translation identifiers as choices:

packages/ra-ui-materialui/src/input/SelectArrayInput.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ import {
7171
* { id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
7272
* { id: 456, first_name: 'Jane', last_name: 'Austen' },
7373
* ];
74-
* const FullNameField = ({ record }) => <span>{record.first_name} {record.last_name}</span>;
74+
* const FullNameField = () => {
75+
* const record = useRecordContext();
76+
* return (<span>{record.first_name} {record.last_name}</span>)
77+
* };
7578
* <SelectArrayInput source="authors" choices={choices} optionText={<FullNameField />}/>
7679
*
7780
* The choices are translated by default, so you can use translation identifiers as choices:

0 commit comments

Comments
 (0)