1- import React from "react" ;
1+ import React , { useEffect } from "react" ;
22import { CodeBlock } from "@atlaskit/code" ;
3+ import { useDispatch } from "react-redux" ;
34
45function ReduxPage ( ) {
56
6- const reduxInstall = `npm install -s react-redux @types/react-redux @reduxjs/toolkit`
7+ const reduxInstall = `npm install -s react-redux @types/react-redux @reduxjs/toolkit`
78
8- const reduxAppStore = `import notificationReducer from "./reducers/notificationReducer";
9+ const reduxAppStore = `// state/appStore.ts
10+ import notificationReducer from "./reducers/notificationReducer";
911import {configureStore} from "@reduxjs/toolkit";
1012import stackReducer from "./reducers/stackReducer";
1113
@@ -18,12 +20,13 @@ export const appStore = configureStore({
1820
1921export type State = ReturnType<typeof appStore.getState>`
2022
21- const reduxRegister = `// index.tsx
23+ const reduxRegister = `// index.tsx
2224<Provider store={appStore}>
2325 <App/>
2426</Provider>`
2527
26- const reduxReducer = `import {Notification} from "../../model/AppModel";
28+ const reduxReducer = `// state/reducers/notificationReducer.ts
29+ import {Notification} from "../../model/AppModel";
2730
2831const initialState: Notification[] = []
2932
@@ -70,7 +73,7 @@ const notificationReducer = (state: Notification[] = initialState, action: Actio
7073
7174export default notificationReducer`
7275
73- const reduxUsage = `// get updating notifications from stack (reloads on change)
76+ const reduxUsage = `// get updating notifications from state (reloads component on state change)
7477const notifications = useSelector((appState: State) => appState.notifications)
7578
7679// update state
@@ -82,47 +85,63 @@ dispatch({
8285 type: 'ADD_NOTIFICATION',
8386 notification: notification
8487})`
88+ const dispatch = useDispatch ( )
89+ useEffect ( ( ) => {
90+ dispatch ( {
91+ type : "SET_MENU"
92+ } )
93+ } , [ ] )
8594
8695 return (
8796 < div >
8897 < h1 > Redux</ h1 >
89- < p > Redux is used for global stack handling. For example for handling notifications</ p >
90-
91- < h5 > Install Redux</ h5 >
92- < p > Not needed if you use this library. It is already included</ p >
93- < br />
94- < CodeBlock
95- language = "bash"
96- text = { reduxInstall }
97- />
98-
99- < h5 > Init appStore</ h5 >
100- < br />
101- < CodeBlock
102- language = "typescript"
103- text = { reduxAppStore }
104- />
105-
106- < h5 > Integrate appStore</ h5 >
107- < br />
108- < CodeBlock
109- language = "tsx"
110- text = { reduxRegister }
111- />
112-
113- < h5 > Create reducer</ h5 >
114- < br />
115- < CodeBlock
116- language = "typescript"
117- text = { reduxReducer }
118- />
119-
120- < h5 > Use and change redux states</ h5 >
121- < br />
122- < CodeBlock
123- language = "typescript"
124- text = { reduxUsage }
125- />
98+ < p > Redux is used for global state handling. For example for handling notifications.</ p >
99+
100+ < div id = "dependencies" menu-name = "Dependencies" className = "menu pd" >
101+ < h5 > Dependencies</ h5 >
102+ < p > This library uses the following dependencies:</ p >
103+ < br />
104+ < CodeBlock
105+ language = "bash"
106+ text = { reduxInstall }
107+ />
108+ </ div >
109+
110+ < div id = "init-appstore" menu-name = "Init AppStore" className = "menu pd" >
111+ < h5 > Init appStore</ h5 >
112+ < br />
113+ < CodeBlock
114+ language = "typescript"
115+ text = { reduxAppStore }
116+ />
117+ </ div >
118+
119+ < div id = "integrate-appstore" menu-name = "Integrate AppStore" className = "menu pd" >
120+ < h5 > Integrate appStore</ h5 >
121+ < br />
122+ < CodeBlock
123+ language = "tsx"
124+ text = { reduxRegister }
125+ />
126+ </ div >
127+
128+ < div id = "create-reducer" menu-name = "Create Reducer" className = "menu pd" >
129+ < h5 > Create reducer</ h5 >
130+ < br />
131+ < CodeBlock
132+ language = "typescript"
133+ text = { reduxReducer }
134+ />
135+ </ div >
136+
137+ < div id = "use-redux" menu-name = "Use Redux States" className = "menu pd" >
138+ < h5 > Use and change redux states</ h5 >
139+ < br />
140+ < CodeBlock
141+ language = "typescript"
142+ text = { reduxUsage }
143+ />
144+ </ div >
126145 </ div >
127146 )
128147}
0 commit comments