Skip to content

Commit 8219644

Browse files
authored
Merge pull request #6498 from marmelab/fix-linktorecord-doc
[Doc] Fix Syntax Error in linkToRecord code snippet
2 parents b0b99a9 + f55c317 commit 8219644

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

docs/Fields.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -1611,19 +1611,20 @@ const UserShow = props => (
16111611

16121612
And now you can use a regular Field component, and the label displays correctly in the Show view.
16131613

1614-
### Linking to other records
1614+
### Linking To Other Records
16151615

1616-
Your custom Field component might need to display a link to another record. React Admin provides a `linkToRecord(basePath, id[, linkType])` method for this purpose.
1616+
A custom Field component might need to display a link to another record. React Admin provides a `linkToRecord(basePath, id[, linkType])` method for this purpose.
16171617

16181618
```js
1619-
import { linkToRecord, useRecordContext } from 'react-admin';
1619+
import { linkToRecord, useRecordContext, useGetOne } from 'react-admin';
16201620
import { Link } from 'react-router-dom';
16211621

1622-
const MyCustomField = () => {
1622+
const AuthorField = () => {
16231623
const post = useRecordContext(props);
1624-
const linkToUser = linkToRecord('/users', post.user_id, 'show');
1624+
const { data, loaded } = useGetOne('users', post.user_id);
1625+
const userShowPage = linkToRecord('/users', post.user_id, 'show');
16251626

1626-
return <Link to={linkToUser}>{seller.username}</Link>;
1627+
return loaded ? <Link to={userShowPage}>{data.username}</Link> : null;
16271628
};
16281629
```
16291630

0 commit comments

Comments
 (0)