From e4596447e52420ed968d6b856bd2be7507493727 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Tue, 10 Aug 2021 17:03:38 +0200 Subject: [PATCH 1/2] [Doc] Fix Syntax Error in linkToRecord code snippet Closes #6497 --- docs/Fields.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/Fields.md b/docs/Fields.md index d77994911da..63921edee08 100644 --- a/docs/Fields.md +++ b/docs/Fields.md @@ -1611,19 +1611,20 @@ const UserShow = props => ( And now you can use a regular Field component, and the label displays correctly in the Show view. -### Linking to other records +### Linking To Other Records -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. +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. ```js -import { linkToRecord, useRecordContext } from 'react-admin'; +import { linkToRecord, useRecordContext, useGetOne } from 'react-admin'; import { Link } from 'react-router-dom'; -const MyCustomField = () => { +const AuthorField = () => { const post = useRecordContext(props); - const linkToUser = linkToRecord('/users', post.user_id, 'show'); + const { data, loaded } = useGetOne('users', post.user_id); + const userShowPage = linkToRecord('/users', post.user_id, 'show'); - return {seller.username}; + return loaded ? {data.username} : null; }; ``` From f55c31774bbc866ca0a0d3e0d1a4a740aa6559b1 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Tue, 10 Aug 2021 17:18:55 +0200 Subject: [PATCH 2/2] Fix typo --- docs/Fields.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Fields.md b/docs/Fields.md index 63921edee08..cd107daa80b 100644 --- a/docs/Fields.md +++ b/docs/Fields.md @@ -1621,7 +1621,7 @@ import { Link } from 'react-router-dom'; const AuthorField = () => { const post = useRecordContext(props); - const { data, loaded } = useGetOne('users', post.user_id); + const { data, loaded } = useGetOne('users', post.user_id); const userShowPage = linkToRecord('/users', post.user_id, 'show'); return loaded ? {data.username} : null;