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_headless/src/content/docs/recipes/Caching.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,6 @@ layout: default
3
3
title: "Caching"
4
4
---
5
5
6
-
# Caching
7
-
8
6
Not hitting the server is the best way to improve a web app performance, and its ecological footprint too (network and datacenter usage account for about 40% of the CO2 emissions in IT). React-admin comes with a built-in cache-first approach called *optimistic rendering*, and it supports caching both at the HTTP level and the application level.
9
7
10
8
## Optimistic Rendering
@@ -86,11 +84,11 @@ Finally, if your API uses GraphQL, it probably doesn't offer HTTP caching.
86
84
87
85
## Application Cache
88
86
89
-
React-admin uses react-query for data fetching. React-query comes with its own caching system, allowing you to skip API calls completely. React-admin calls this the *application cache*. It's a good way to overcome the limitations if the HTTP cache. **This cache is opt-in** - you have to enable it by setting a custom `queryClient` in your `<Admin>` with a specific `staleTime` option.
87
+
React-admin uses react-query for data fetching. React-query comes with its own caching system, allowing you to skip API calls completely. React-admin calls this the *application cache*. It's a good way to overcome the limitations if the HTTP cache. **This cache is opt-in** - you have to enable it by setting a custom `queryClient` in your `<CoreAdminContext>` with a specific `staleTime` option.
Copy file name to clipboardExpand all lines: docs_headless/src/content/docs/recipes/UnitTesting.md
+29-31Lines changed: 29 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,47 +3,45 @@ layout: default
3
3
title: "Unit Testing"
4
4
---
5
5
6
-
# Unit Testing
7
-
8
6
React-admin relies heavily on unit tests (powered by [Jest](https://facebook.github.io/jest/) and [react-testing-library](https://testing-library.com/docs/react-testing-library/intro)) to ensure that its code is working as expected.
9
7
10
8
That means that each individual component and hook can be tested in isolation. That also means that if you have to test your own components and hooks based on react-admin, this should be straightforward.
11
9
12
-
## AdminContext Wrapper
10
+
## CoreAdminContext Wrapper
13
11
14
-
Some of react-admin's components depend on a context for translation, theming, data fetching, etc. If you write a component that depends on a react-admin component, chances are the test runner will complain about a missing context.
12
+
Some of react-admin's components depend on a context for translation, data fetching, etc. If you write a component that depends on a react-admin component, chances are the test runner will complain about a missing context.
15
13
16
-
Wrap your tested component inside `<AdminContext>` to avoid this problem:
14
+
Wrap your tested component inside `<CoreAdminContext>` to avoid this problem:
`<AdminContext>` accepts the same props as `<Admin>`, so you can pass a custom `dataProvider`, `authProvider`, or `i18nProvider` for testing purposes.
53
+
`<CoreAdminContext>` accepts the same props as `<Admin>`, so you can pass a custom `dataProvider`, `authProvider`, or `i18nProvider` for testing purposes.
56
54
57
55
For instance, if the component to test calls the `useGetOne` hook:
The react-admin Store is persistent. This means that if a test modifies an item in the store, the updated value will be changed in the next test. This will cause seemingly random test failures when you use `useStore()` in your tests, or any feature depending on the store (e.g. `<DataTable>`row selection, sidebar state, language selection).
103
+
The react-admin Store is persistent. This means that if a test modifies an item in the store, the updated value will be changed in the next test. This will cause seemingly random test failures when you use `useStore()` in your tests, or any feature depending on the store (e.g. row selection, sidebar state, language selection).
106
104
107
105
To isolate your unit tests, pass a new `memoryStore` at each test:
0 commit comments