Skip to content

Commit e528407

Browse files
Touching up Tutorial.md with improvements to TypeScript examples.
1 parent d94cc69 commit e528407

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

docs/Tutorial.md

+12-10
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ import { UserList } from "./users";
459459

460460
const App = () => (
461461
<Admin dataProvider={dataProvider}>
462-
+ <Resource name="users" list={UserList} />
463-
<Resource name="posts" list={ListGuesser} />
462+
<Resource name="users" list={UserList} />
463+
+ <Resource name="posts" list={ListGuesser} />
464464
</Admin>
465465
);
466466

@@ -755,7 +755,7 @@ export const PostEdit = () => (
755755

756756
[![Post Edit Title](./img/tutorial_post_title.png)](./img/tutorial_post_title.png)
757757

758-
This component uses the same `useRecordContext` hook as the custom `<UrlField>` commponent described earlier.
758+
This component uses the same `useRecordContext` hook as the custom `<UrlField>` component described earlier.
759759

760760
As users can access the post editing page directly by its url, the `<PostTitle>` component may render *without a record* while the `<Edit>` component is fetching it. That's why you must always check that the `record` returned by `useRecordContext` is defined before using it - as in `PostTitle` above.
761761

@@ -845,9 +845,11 @@ For this tutorial, since there is no public authentication API, we can use a fak
845845

846846
The `authProvider` must expose 5 methods, each returning a `Promise`:
847847

848-
```jsx
848+
```js
849849
// in src/authProvider.ts
850-
export const authProvider = {
850+
import {AuthProvider} from "react-admin";
851+
852+
export const authProvider: AuthProvider = {
851853
// called when the user attempts to log in
852854
login: ({ username }) => {
853855
localStorage.setItem("username", username);
@@ -924,13 +926,13 @@ React-admin calls the Data Provider with one method for each of the actions of t
924926
The code for a Data Provider for the `my.api.url` API is as follows:
925927

926928
```js
927-
import { fetchUtils } from "react-admin";
929+
import { DataProvider, fetchUtils } from "react-admin";
928930
import { stringify } from "query-string";
929931

930932
const apiUrl = 'https://my.api.com/';
931933
const httpClient = fetchUtils.fetchJson;
932934

933-
export const dataProvider= {
935+
export const dataProvider: DataProvider = {
934936
getList: (resource, params) => {
935937
const { page, perPage } = params.pagination;
936938
const { field, order } = params.sort;
@@ -943,7 +945,7 @@ export const dataProvider= {
943945

944946
return httpClient(url).then(({ headers, json }) => ({
945947
data: json,
946-
total: parseInt(headers.get('content-range').split('/').pop(), 10),
948+
total: parseInt((headers.get('content-range') || "0").split('/').pop()!, 10),
947949
}));
948950
},
949951

@@ -975,7 +977,7 @@ export const dataProvider= {
975977

976978
return httpClient(url).then(({ headers, json }) => ({
977979
data: json,
978-
total: parseInt(headers.get('content-range').split('/').pop(), 10),
980+
total: parseInt((headers.get('content-range') || "0").split('/').pop()!, 10),
979981
}));
980982
},
981983

@@ -1040,4 +1042,4 @@ React-admin was built with customization in mind. You can replace any react-admi
10401042

10411043
Now that you've completed the tutorial, continue your journey with [the Features chapter](./Features.md), which lists all the features of react-admin.
10421044

1043-
**Tip**: To help you close the gap between theoritical knowledge and practical experience, take advantage of the react-admin [Demos](./Demos.md). They are great examples of how to use react-admin in a real world application. They also show the best practices for going beyond simple CRUD apps.
1045+
**Tip**: To help you close the gap between theoretical knowledge and practical experience, take advantage of the react-admin [Demos](./Demos.md). They are great examples of how to use react-admin in a real world application. They also show the best practices for going beyond simple CRUD apps.

examples/tutorial/src/authProvider.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export const authProvider = {
1+
import { AuthProvider } from 'react-admin';
2+
3+
export const authProvider: AuthProvider = {
24
// called when the user attempts to log in
35
login: ({ username }: { username: string }) => {
46
localStorage.setItem('username', username);

0 commit comments

Comments
 (0)