You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Upgrade.md
+26-1Lines changed: 26 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,8 @@ React-admin v5 mostly focuses on removing deprecated features and upgrading depe
47
47
-[Global Server Side Validation Error Message Must Be Passed Via The `root.serverError` Key](#global-server-side-validation-error-message-must-be-passed-via-the-rootservererror-key)
48
48
-[TypeScript](#typescript)
49
49
-[Fields Components Requires The source Prop](#fields-components-requires-the-source-prop)
50
-
-[`useRecordContext` Returns undefined When No Record Is Available](#userecordcontext-returns-undefined-when-no-record-is-available)
50
+
-[`useRecordContext` Returns `undefined` When No Record Is Available](#userecordcontext-returns-undefined-when-no-record-is-available)
51
+
-[`useAuthProvider` Returns `undefined` When No `authProvider` Is Available](#useauthprovider-returns-undefined-when-no-authprovider-is-available)
51
52
-[Page Contexts Are Now Types Instead of Interfaces](#page-contexts-are-now-types-instead-of-interfaces)
52
53
-[Stronger Types For Page Contexts](#stronger-types-for-page-contexts)
53
54
-[EditProps and CreateProps now expect a children prop](#editprops-and-createprops-now-expect-a-children-prop)
### `useAuthProvider` Returns `undefined` When No `authProvider` Is Available
1091
+
1092
+
The `useAuthProvider` hook returns the current `authProvider`. Since the `authProvider` is optional, this context may be empty. Thus, the return type for `useAuthProvider` has been modified to `AuthProvider | undefined` instead of `AuthProvider` to denote this possibility.
1093
+
1094
+
As a consequence, the TypeScript compilation of your project may fail if you don't check the existence of the `authProvider` before reading it.
1095
+
1096
+
To fix this error, your code should handle the case where `useAuthProvider` returns `undefined`:
1097
+
1098
+
```diff
1099
+
const useGetPermissions = (): GetPermissions => {
1100
+
const authProvider = useAuthProvider();
1101
+
const getPermissions = useCallback(
1102
+
(params: any = {}) =>
1103
+
+ authProvider ?
1104
+
authProvider
1105
+
.getPermissions(params)
1106
+
.then(result => result ?? null)
1107
+
+ : Promise.resolve([]),
1108
+
[authProvider]
1109
+
);
1110
+
return getPermissions;
1111
+
};
1112
+
```
1113
+
1089
1114
### Page Contexts Are Now Types Instead of Interfaces
1090
1115
1091
1116
The return type of page controllers is now a type. If you were using an interface extending one of:
0 commit comments