Skip to content

Commit a4e5f1a

Browse files
authored
Merge pull request #9604 from marmelab/doc-fix-custom-field-tutorial
[Doc] Fix Tutorial misses URL scheme in custom Field
2 parents 8c16858 + 7b549ff commit a4e5f1a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

docs/Tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ For instance, the `website` field looks like a URL. Instead of displaying it as
367367

368368
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.
369369

370-
## Writing A Custom Field
370+
## Writing A Custom Field
371371

372372
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").
373373

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

386386
export default MyUrlField;

examples/tutorial/src/MyUrlField.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import LaunchIcon from '@mui/icons-material/Launch';
55
const MyUrlField = ({ source }: { source: string }) => {
66
const record = useRecordContext();
77
return record ? (
8-
<Link href={record[source]} sx={{ textDecoration: 'none' }}>
8+
<Link
9+
href={`http://${record[source]}`}
10+
onClick={e => e.stopPropagation()}
11+
>
912
{record[source]}
1013
<LaunchIcon sx={{ fontSize: 15, ml: 1 }} />
1114
</Link>

0 commit comments

Comments
 (0)