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 Tutorial misses URL scheme in custom Field #9604

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions docs/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ For instance, the `website` field looks like a URL. Instead of displaying it as

This reflects the early stages of development with react-admin: let the guesser component bootstrap a basic page, then tweak the generated code to better match your business logic.

## Writing A Custom Field
## Writing A Custom Field

In react-admin, fields are just React components. When rendered, they grab the `record` fetched from the API (e.g. `{ "id": 2, "name": "Ervin Howell", "website": "anastasia.net", ... }`) using a custom hook, and use the `source` field (e.g. `website`) to get the value they should display (e.g. "anastasia.net").

Expand All @@ -380,7 +380,7 @@ import { useRecordContext } from "react-admin";
const MyUrlField = ({ source }: { source: string }) => {
const record = useRecordContext();
if (!record) return null;
return <a href={record[source]}>{record[source]}</a>;
return <a href={`http://${record[source]}`}>{record[source]}</a>;
};

export default MyUrlField;
Expand Down
5 changes: 4 additions & 1 deletion examples/tutorial/src/MyUrlField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import LaunchIcon from '@mui/icons-material/Launch';
const MyUrlField = ({ source }: { source: string }) => {
const record = useRecordContext();
return record ? (
<Link href={record[source]} sx={{ textDecoration: 'none' }}>
<Link
href={`http://${record[source]}`}
onClick={e => e.stopPropagation()}
>
{record[source]}
<LaunchIcon sx={{ fontSize: 15, ml: 1 }} />
</Link>
Expand Down
Loading