app,create-app: update to use app.createRoot()

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-12-08 11:43:23 +01:00
parent 62e58de887
commit 0e91c1196d
3 changed files with 39 additions and 16 deletions
+33 -2
View File
@@ -2,7 +2,7 @@
'@backstage/create-app': patch
---
Updated the app template to use the new `AppRouter` component instead of `app.getRouter()`.
Updated the app template to use the new `AppRouter` component instead of `app.getRouter()`, as well as `app.createRoot()` instead of `app.getProvider()`.
To apply this change to an existing app, make the following change to `packages/app/src/App.tsx`:
@@ -12,6 +12,37 @@ To apply this change to an existing app, make the following change to `packages/
...
const AppProvider = app.getProvider();
-const AppProvider = app.getProvider();
-const AppRouter = app.getRouter();
...
-const App = () => (
+export default app.createRoot(
- <AppProvider>
+ <>
<AlertDisplay />
<OAuthRequestDialog />
<AppRouter>
<Root>{routes}</Root>
</AppRouter>
- </AppProvider>
+ </>,
);
```
The final export step should end up looking something like this:
```tsx
export default app.createRoot(
<>
<AlertDisplay />
<OAuthRequestDialog />
<AppRouter>
<Root>{routes}</Root>
</AppRouter>
</>,
);
```
Note that `app.createRoot()` accepts a React element, rather than a component.
+3 -7
View File
@@ -145,8 +145,6 @@ const app = createApp({
},
});
const AppProvider = app.getProvider();
const routes = (
<FlatRoutes>
<Route path="/" element={<Navigate to="catalog" />} />
@@ -277,14 +275,12 @@ const routes = (
</FlatRoutes>
);
const App = () => (
<AppProvider>
export default app.createRoot(
<>
<AlertDisplay transientTimeoutMs={2500} />
<OAuthRequestDialog />
<AppRouter>
<Root>{routes}</Root>
</AppRouter>
</AppProvider>
</>,
);
export default App;
@@ -53,8 +53,6 @@ const app = createApp({
},
});
const AppProvider = app.getProvider();
const routes = (
<FlatRoutes>
<Route path="/" element={<Navigate to="catalog" />} />
@@ -96,14 +94,12 @@ const routes = (
</FlatRoutes>
);
const App = () => (
<AppProvider>
export default app.createRoot(
<>
<AlertDisplay />
<OAuthRequestDialog />
<AppRouter>
<Root>{routes}</Root>
</AppRouter>
</AppProvider>
</>,
);
export default App;