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] Tutorial: Fix typos, snippets and file extensions #8607

Merged
merged 4 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 12 additions & 10 deletions docs/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ import { UserList } from "./users";

const App = () => (
<Admin dataProvider={dataProvider}>
+ <Resource name="users" list={UserList} />
<Resource name="posts" list={ListGuesser} />
<Resource name="users" list={UserList} />
+ <Resource name="posts" list={ListGuesser} />
</Admin>
);

Expand Down Expand Up @@ -755,7 +755,7 @@ export const PostEdit = () => (

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

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

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.

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

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

```jsx
```js
// in src/authProvider.ts
export const authProvider = {
import {AuthProvider} from "react-admin";
slax57 marked this conversation as resolved.
Show resolved Hide resolved

export const authProvider: AuthProvider = {
// called when the user attempts to log in
login: ({ username }) => {
localStorage.setItem("username", username);
Expand Down Expand Up @@ -924,13 +926,13 @@ React-admin calls the Data Provider with one method for each of the actions of t
The code for a Data Provider for the `my.api.url` API is as follows:

```js
import { fetchUtils } from "react-admin";
import { DataProvider, fetchUtils } from "react-admin";
slax57 marked this conversation as resolved.
Show resolved Hide resolved
import { stringify } from "query-string";

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

export const dataProvider= {
export const dataProvider: DataProvider = {
getList: (resource, params) => {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
Expand All @@ -943,7 +945,7 @@ export const dataProvider= {

return httpClient(url).then(({ headers, json }) => ({
data: json,
total: parseInt(headers.get('content-range').split('/').pop(), 10),
total: parseInt((headers.get('content-range') || "0").split('/').pop() || 0, 10),
}));
},

Expand Down Expand Up @@ -975,7 +977,7 @@ export const dataProvider= {

return httpClient(url).then(({ headers, json }) => ({
data: json,
total: parseInt(headers.get('content-range').split('/').pop(), 10),
total: parseInt((headers.get('content-range') || "0").split('/').pop() || 0, 10),
}));
},

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

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

**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.
**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.
4 changes: 3 additions & 1 deletion examples/tutorial/src/authProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const authProvider = {
import { AuthProvider } from 'react-admin';
erikvanderwerf marked this conversation as resolved.
Show resolved Hide resolved

export const authProvider: AuthProvider = {
// called when the user attempts to log in
login: ({ username }: { username: string }) => {
localStorage.setItem('username', username);
Expand Down