File tree Expand file tree Collapse file tree 4 files changed +28
-14
lines changed
examples/lazy-injection/kitchen-sink/src Expand file tree Collapse file tree 4 files changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,9 @@ const App = () => {
2323 < summary onClick = { ( ) => startTransition ( toggleCounter ) } >
2424 Counter example (lazy)
2525 </ summary >
26- < Suspense > { counterOpen && < Counter /> } </ Suspense >
26+ < Suspense fallback = "Loading counter" >
27+ { counterOpen && < Counter /> }
28+ </ Suspense >
2729 </ details >
2830 < p >
2931 Edit < code > src/App.tsx</ code > and save to reload.
@@ -32,7 +34,9 @@ const App = () => {
3234 < summary onClick = { ( ) => startTransition ( toggleQuotes ) } >
3335 Quotes example (lazy)
3436 </ summary >
35- < Suspense > { quotesOpen && < Quotes /> } </ Suspense >
37+ < Suspense fallback = "Loading quotes" >
38+ { quotesOpen && < Quotes /> }
39+ </ Suspense >
3640 </ details >
3741 < span >
3842 < span > Learn </ span >
Original file line number Diff line number Diff line change 11import { combineSlices } from "@reduxjs/toolkit"
22import { todoSlice } from "../features/todos/todoSlice"
3- import { commentSlice } from "../features/todos/commentSlice"
43
54export interface LazyLoadedSlices { }
65
76// `combineSlices` automatically combines the reducers using
87// their `reducerPath`s, therefore we no longer need to call `combineReducers`.
9- export const rootReducer = combineSlices (
10- todoSlice ,
11- commentSlice ,
12- ) . withLazyLoadedSlices < LazyLoadedSlices > ( )
8+ export const rootReducer =
9+ combineSlices ( todoSlice ) . withLazyLoadedSlices < LazyLoadedSlices > ( )
Original file line number Diff line number Diff line change 11import { useAppSelector } from "../../app/hooks"
22import { AddTodo } from "./AddTodo"
3- import { Todo } from "./Todo"
43import { selectTodoIds } from "./todoSlice"
54import styles from "./Todos.module.css"
5+ import { lazily } from "react-lazily"
6+ import { Suspense } from "react"
7+
8+ const { Todo } = lazily ( ( ) => import ( "./Todo" ) )
69
710export function Todos ( ) {
811 const todoIds = useAppSelector ( selectTodoIds )
912 return (
1013 < div className = { styles . todos } >
1114 < AddTodo />
12- < div className = { styles . todosList } >
13- { todoIds . map ( id => (
14- < Todo key = { id } id = { id } />
15- ) ) }
16- </ div >
15+ < Suspense fallback = "Loading todos" >
16+ < div className = { styles . todosList } >
17+ { todoIds . map ( id => (
18+ < Todo key = { id } id = { id } />
19+ ) ) }
20+ </ div >
21+ </ Suspense >
1722 </ div >
1823 )
1924}
Original file line number Diff line number Diff line change 1+ import type { WithSlice } from "@reduxjs/toolkit"
12import { createEntityAdapter , createSelector , nanoid } from "@reduxjs/toolkit"
23import { createAppSlice } from "../../app/createAppSlice"
34import { deleteTodo } from "./todoSlice"
5+ import { rootReducer } from "../../app/reducer"
46
57export interface Comment {
68 id : string
@@ -49,11 +51,17 @@ export const commentSlice = createAppSlice({
4951
5052export const { addComment, deleteComment } = commentSlice . actions
5153
54+ declare module "../../app/reducer" {
55+ interface LazyLoadedSlices extends WithSlice < typeof commentSlice > { }
56+ }
57+
58+ const injectedCommentSlice = commentSlice . injectInto ( rootReducer )
59+
5260export const {
5361 selectAll : selectAllComments ,
5462 selectById : selectCommentById ,
5563 selectEntities : selectCommentEntities ,
5664 selectIds : selectCommentIds ,
5765 selectTotal : selectCommentTotal ,
5866 selectCommentsByTodoId,
59- } = commentSlice . selectors
67+ } = injectedCommentSlice . selectors
You can’t perform that action at this time.
0 commit comments