Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Fix Syntax Error in linkToRecord code snippet #6498

Merged
merged 2 commits into from
Aug 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/Fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Link to={linkToUser}>{seller.username}</Link>;
return loaded ? <Link to={userShowPage}>{data.username}</Link> : null;
};
```

Expand Down