@@ -273,13 +273,13 @@ But on desktop, `<SimpleList>` takes too much space for a low information densit
273273
274274To do so, we'll use [ the ` useMediaQuery ` hook] ( https://mui.com/material-ui/react-use-media-query/ ) from Material UI:
275275
276- ``` jsx
276+ ``` tsx
277277// in src/users.tsx
278- import { useMediaQuery } from " @mui/material" ;
278+ import { useMediaQuery , Theme } from " @mui/material" ;
279279import { List , SimpleList , Datagrid , TextField , EmailField } from " react-admin" ;
280280
281281export const UserList = () => {
282- const isSmall = useMediaQuery ((theme ) => theme .breakpoints .down (" sm" ));
282+ const isSmall = useMediaQuery < Theme > ((theme ) => theme .breakpoints .down (" sm" ));
283283 return (
284284 <List >
285285 { isSmall ? (
@@ -372,11 +372,11 @@ In react-admin, fields are just React components. When rendered, they grab the `
372372
373373That means that you can do the same to write a custom Field. For instance, here is a simplified version of the ` <UrlField> ` :
374374
375- ``` jsx
375+ ``` tsx
376376// in src/MyUrlField.tsx
377377import { useRecordContext } from " react-admin" ;
378378
379- const MyUrlField = ({ source }) => {
379+ const MyUrlField = ({ source }: { source : string } ) => {
380380 const record = useRecordContext ();
381381 if (! record ) return null ;
382382 return <a href = { record [source ]} >{ record [source ]} </a >;
@@ -415,13 +415,13 @@ The `<MyUrlField>` component is a perfect opportunity to illustrate how to custo
415415React-admin relies on [ Material UI] ( https://mui.com/material-ui/getting-started/overview/ ) , a set of React components modeled after Google's [ Material Design Guidelines] ( https://material.io/ ) . All Material UI components (and most react-admin components) support a prop called ` sx ` , which allows custom inline styles. Let's take advantage of the ` sx ` prop to remove the underline from the link and add an icon:
416416
417417{% raw %}
418- ``` jsx
418+ ``` tsx
419419// in src/MyUrlField.tsx
420420import { useRecordContext } from " react-admin" ;
421421import { Link } from " @mui/material" ;
422422import LaunchIcon from " @mui/icons-material/Launch" ;
423423
424- const MyUrlField = ({ source }) => {
424+ const MyUrlField = ({ source }: { source : string } ) => {
425425 const record = useRecordContext ();
426426 return record ? (
427427 <Link href = { record [source ]} sx = { { textDecoration: " none" }} >
@@ -877,13 +877,13 @@ For this tutorial, since there is no public authentication API, we can use a fak
877877
878878The ` authProvider ` must expose 5 methods, each returning a ` Promise ` :
879879
880- ``` js
880+ ``` ts
881881// in src/authProvider.ts
882+ import { AuthProvider } from " react-admin" ;
882883
883- // TypeScript users must reference the type: `AuthProvider`
884- export const authProvider = {
884+ export const authProvider: AuthProvider = {
885885 // called when the user attempts to log in
886- login : ({ username }) => {
886+ login : ({ username }: { username : string } ) => {
887887 localStorage .setItem (" username" , username );
888888 // accept all username/password combinations
889889 return Promise .resolve ();
@@ -894,7 +894,7 @@ export const authProvider = {
894894 return Promise .resolve ();
895895 },
896896 // called when the API returns an error
897- checkError : ({ status }) => {
897+ checkError : ({ status }: { status : number } ) => {
898898 if (status === 401 || status === 403 ) {
899899 localStorage .removeItem (" username" );
900900 return Promise .reject ();
@@ -962,16 +962,15 @@ React-admin calls the Data Provider with one method for each of the actions of t
962962
963963The code for a Data Provider for the ` my.api.url ` API is as follows:
964964
965- ``` js
965+ ``` ts
966966// in src/dataProvider.ts
967- import { fetchUtils } from " react-admin" ;
967+ import { DataProvider , fetchUtils } from " react-admin" ;
968968import { stringify } from " query-string" ;
969969
970970const apiUrl = ' https://my.api.com/' ;
971971const httpClient = fetchUtils .fetchJson ;
972972
973- // TypeScript users must reference the type `DataProvider`
974- export const dataProvider = {
973+ export const dataProvider: DataProvider = {
975974 getList : (resource , params ) => {
976975 const { page, perPage } = params .pagination ;
977976 const { field, order } = params .sort ;
0 commit comments